1

下面的代码在 Mozilla Firefox、Internet Explorer 中运行良好,但在 google chrome 中出现上述错误。

adminlogin.jsp

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Admin Role Page</title>
<script type="text/javascript">
function submitForm()
{
document.forms[0].action = "UsrAction.do?";
document.forms[0].submit();
}
</script>
</head>
<body>
<html:form action="/UsrAction" >
<html:submit property="method" value="lodable" onclick="submitForm() " />
<html:submit property="method" value="adduser" onclick="submitForm()" /> 
<html:submit  property="method" value="addprogram" onclick="submitForm()"/>
</html:form>
</body>
</html>

struts-config.xml

<action input="/adminLogin.jsp" parameter="method" name="UsrForm" path="/UsrAction" scope="session" type="com.me.action.UsrAction">
<forward name="lodable" path="/pages/Lodable.jsp" />
<forward name="adduser" path="/pages/add.jsp" />
<forward name="addprog" path="/pages/program.jsp" />
</action>

UerAction.java

public class UsrAction extends DispatchAction {
private final static String lodable = "lodable";
private final static String adduser = "adduser";
private final static String addprog = "addprog";
public ActionForward lodable(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception {
UsrForm userForm = (UsrForm) form;
lgnDTO login = new lgnDTO();
request.setAttribute("login", login.getUsername());  
return mapping.findForward(lodable);
}

public ActionForward adduser(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception {
UsrForm userForm = (UsrForm) form;
lgnDTO login = new lgnDTO();
return mapping.findForward(addprog);
}

public ActionForward addprogram(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception {
UsrForm userForm = (UsrForm) form;
lgnDTO login = new lgnDTO();
return mapping.findForward(adduser);
}
}

错误日志

type Exception report

message Request[/UsrAction] does not contain handler parameter named 'method'. This may be caused by whitespace in the label text.

description The server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Request[/UsrAction] does not contain handler parameter named 'method'.  This may be caused by whitespace in the label text.
    org.apache.struts.actions.DispatchAction.unspecified(DispatchAction.java:197)
    org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:245)
    org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170)
    org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
    org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.39 logs.
4

2 回答 2

2

我认为由于您没有在 URL 中提及参数“方法”,因此您会收到错误消息。我不确定 IE 和 FF 是如何工作的,但如果你像 UsrAction.do?method=lodable我相信的那样构建 URL,它也应该在 chrome 中工作。

于 2014-03-12T07:02:45.337 回答
2

异常的原因是您parameter="method" 在 Struts 配置文件中添加了一个参数,并且系统现在正在该变量中查找您在代码中未提供的方法名称。

您应该使用 hidden from property 来提供方法名称以避免异常。

<input type="hidden" name="method" value="YourMethodName"/>

希望这会对某人有所帮助,

于 2015-05-18T05:08:27.793 回答