以下代码在Mozila Firefox,Internet Explorer中工作正常,但在谷歌浏览器中出现以上错误。
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.
答案 0 :(得分:2)
我认为,由于您未在URL中提及参数'method',因此您收到错误消息。我不确定IE和FF是如何工作的,但如果你构造的URL就像
UsrAction.do?method=lodable
我相信,它也适用于chrome。
答案 1 :(得分:2)
异常的原因是您在Struts配置文件中添加了一个参数parameter="method"
,系统现在正在查找该变量中的方法名称,而您在代码中未提供该名称。
您应该使用hidden from属性来提供方法名称以避免异常。
<input type="hidden" name="method" value="YourMethodName"/>
希望这会对某人有所帮助,