Struts标记会覆盖操作中的上下文路径

时间:2014-03-09 13:25:55

标签: java jsp java-ee struts2 actionresult

我有一个页面,其中包含重定向到struts操作的链接,当我通过URL Action重定向时,该操作正常。我需要再次调用该操作,此时上下文路径显示错误。如果我在命名空间中给出这个,那么URL操作就会混乱。怎么解决这个?

文件在这里:

index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Online Test Taking System</title>
</head>
<body>
<s:url action="viewuncomputedlist.action" var="viewremlist" />

<a href="<s:url action='viewuncomputedlist'/>"> Here you GO! </a>
</body>
</html>

struts.xml

<?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>
<package name="user" namespace="/" extends="struts-default">
    <action name="compute" class="com.action.ComputeScore" method="computeMethod">
        <result name="redirect" type="chain">viewuncomputedlist</result>
    </action>
    <action name="viewuncomputedlist" class="com.action.FetchRemUser">
        <result name="success">viewList.jsp</result>
    </action>
</package>
</struts>

当我在某个提交表单中调用该操作时,它会直接从WebContent调用它。但是所有JSP文件都在WebContent/jsp/rams/result/

1 个答案:

答案 0 :(得分:1)

除非你知道自己在做什么,否则你应该使用JSP的绝对路径名

<result name="success">/jsp/rams/result/viewList.jsp</result>