struts2设置默认首页

在默认情况下,我们一般希望。当我们在浏览器中输入127.0.0.1:8080/project_name时候跳到项目的首页,那么在struts中我们这么设置呢?光加上<default-action-ref name="user" />是不够的,由于struts2默认是index.jsp为首页,所以我们把index.jsp删除了即可了,struts2从web.xml中找到项目的入口index.jsp可是index.jsp不存在了,那么<default-action-ref name="user" />这个配置就起作用了。user是你设置的action。

以下给出我的配置

<?xml version="1.0" encoding="UTF-8" ?

> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts> <constant name="struts.action.extension" value=",do,action" /> <constant name="struts.i18n.encoding" value="utf-8" /> <constant name="struts.devMode" value="true"></constant> <package name="front" namespace="/" extends="struts-default"> <default-action-ref name="user" /><!--在这里设置--> <action name="user" class="com.sunny.action.Login"> <result name="login">/login.jsp</result> </action> </package> </struts>


然后我们在com.sunny.action.Login类中写一个execute函数就好了。注意这里能够不用继承ActionSupport,Struts2会通过反射技术,自己主动的调用我们自已写的execure函数。那么我们自已的默认首页就写好了

posted @ 2017-05-02 21:58  zhchoutai  阅读(3052)  评论(0编辑  收藏  举报