Icce___ 2015-06-19 08:23 采纳率: 66.7%
浏览 7621
已结题

struts2 action找不到404

刚学习struts2,做到登录功能的时候登录按钮点击之后就显示action404的页面
我的工程结构是这样的
图片说明

web.xml

 <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  <display-name>ieZhan</display-name>
  <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter</filter-class>
    </filter>
  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <welcome-file-list>  
    <welcome-file>index.jsp</welcome-file>  
  </welcome-file-list>  
</web-app>

struts.xml


<package name="struts2" extends="struts-default" namespace="/">
      <action name="login" class="com.login.struts2.loginAction">
          <result name="success" type="redirect">/aboutus.jsp</result>
          <result name="failer" type="redirect">/contactus.jsp</result>    
      </action>
</package>

jsp页面中的form代码

 <s:form action="login" >
            <ul class="login_cont">
                <li class="f14">会员登录</li>
                <li class="login_ipt"><p><span class="fl tr">账号:</span><input type="text" class="login_txt fl" name="username"/></p></li>
                <li class="login_ipt"><p><span class="fl tr">密码:</span><input type="password" class="login_txt fl" name="password"/></p></li>
                <li><a href="#" class="fr">忘记登录密码?</a><label><input type="checkbox" class="remember_psw" />记住密码</label></li>
                <li class="mt10"><button class="login_button login_button_signup" type="submit" >登录</button></li>
            </ul>
            </s:form>

在启动tomcat的时候有出现警告
六月 19, 2015 3:59:32 下午 com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
警告: No configuration found for the specified action: 'loginAction' in namespace: '/pages'. Form action defaulting to 'action' attribute's literal value.
六月 19, 2015 3:59:33 下午 com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
警告: No configuration found for the specified action: 'loginAction' in namespace: '/pages'. Form action defaulting to 'action' attribute's literal value.

我看了下在页面上的action的url是
图片说明

我试过加namespace=“/” 路径变成/ieZhan/login 也不行
希望有好心人帮忙解决下。

  • 写回答

9条回答

  • SimbaLi123 2015-06-19 08:41
    关注
    在页面上面加上
    <%  
    String path = request.getContextPath();  
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  
    %> 
    
    form的  action里面写
    action="<%=basePath%>login"
    
    评论

报告相同问题?

悬赏问题

  • ¥20 为什么我写出来的绘图程序是这样的,有没有lao哥改一下
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败