struts配置

来源:互联网 发布:施工日记的软件 编辑:程序博客网 时间:2024/05/20 19:31

关于:struts.xml;

<struts>


    <constant name="struts.devMode" value="true" />
    <package name="default" namespace="/control/test" extends="struts-default">
       <action name="hello" class="com.action.LoginAction" method="execute">
        <result name="12">
                /WEB-INF/hello.jsp
            </result>
        </action>
    </package>
</struts>

//////namespace="/control/test";不能设置成namespace="/":或者设置为namespace="";都不对!


关于:web.xml

 <display-name>baidu</display-name>
  
   <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>


    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
   
  </welcome-file-list>
  


关于:LoginAction

public class LoginAction  {//该类继承了ActionSupport类。这样就可以直接使用SUCCESS, LOGIN等变量和重写execute等方法


 private static final long serialVersionUID = 1L;
 private String username;
 private String password;
 
 public String getUsername() {
  return username;
 }
 public void setUsername(String username) {
  this.username = username;
 }
 public String getPassword() {
  return password;
 }
 public void setPassword(String password) {
  this.password = password;
 }


 //@Override
 public String execute() throws Exception {
  //if("haha".equals(username) && "hehe".equals(password))//如果登录的用户名=haha并且密码=hehe,就返回SUCCESS;否则,返回LOGIN
   return "12";
  //return LOGIN;
 }


0 0
原创粉丝点击