Reputation: 26428
I have a web application with url : localhost:8080/appname/views/welcome.html. So instead of typing the whole url, I want my application to open welcome.html when user types till localhost:8080/appname. So i have done the following changes in my spring config xml.
<mvc:annotation-driven />
<mvc:resources mapping="/static/**" location="/" />
<mvc:view-controller path="/" view-name="welcome" />
<mvc:default-servlet-handler />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/views/" />
<property name="suffix" value=".html" />
</bean>
but with this configuration, I am not able to bring my application up in browser instead getting 404 error.
need help on what I doing wrong.
Upvotes: 0
Views: 551
Reputation: 3016
You can also create a Spring action and use the value attribute in the @RequestMapping to specify what url to call or invoke that action. When that action is called you return the name of the page which in this case is welcome.html. So you can use this approach to load the welcome.html page by telling to action to map to "/".
@Controller
public class CustomController {
@RequestMapping (value = {"/","home"}, method = RequestMethod.GET)
public String home ()
{
return "welcome";
}
}
so localhost:8080/app-name/
and
localhost:8080/app-name/home
Upvotes: 1
Reputation: 23226
You can do that by adding the following to your web.xml.
<welcome-file-list>
<welcome-file>/views/welcome.html</welcome-file>
</welcome-file-list>
Upvotes: 1