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函数。那么我们自已的默认首页就写好了


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM