日期:2014-05-17  浏览次数:20673 次

新人求救 struts2 超链接跳转错误
struts.xml
Java code

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <constant name="struts.i18n.encoding" value="utf-8" />
    <constant name="struts.devMode" value="true" />
    <constant name="struts.configuration.xml.reload" value="true"/>
    <include file="struts-default.xml"/>
    
    <package name="Login" namespace="/" extends="struts-default">
        <action name="login" class="suncw.demo.action.LoginAction">
            <result name="input">/login.jsp</result>
            <result name="success">/index.jsp</result>
            
        </action>
    </package>

</struts>



login.jsp
Java code

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>登陆</title>
  </head>
  <body>
 
  <s:form action="login.action" method="post">
      <s:textfield name="user.username" label="用户"></s:textfield>
     <s:textfield name="user.password" label="密码"></s:textfield>     
      <s:submit value="提交"></s:submit>      
   
  </s:form>
     <a href="Copy">aaaad</a>
  </body>
</html>



Copy.jsp
Java code

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>登陆</title>
  </head>
  <body>
 dfsafdasfd
  
  
  </body>
</html>



我希望的是 点击login.jsp里的超链接能跳到Copy页面 但是提示404
HTTP Status 404 - /strDemo/Copy

type Status report

message /strDemo/Copy

description The requested resource (/strDemo/Copy) is not available.
如果单独访问Copy.jsp能访问到
求助~

------解决方案--------------------
Login/login.action
------解决方案--------------------
<a href="Copy.jsp">aaaad</a>
------解决方案--------------------
XML code

//看看web.xml这里url-pattern里的URL路径有没有配置错误
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>

------解决方案--------------------
路径的问题吧,我也出现过,你把路径改一下,或者 把文件放其他地方试一试