JSP 请求[/UsrAction]不包含名为“method”的处理程序参数,这可能是由标签文本中的空格导致的

yuvru6vn  于 2022-12-07  发布在  其他
关注(0)|答案(3)|浏览(73)

以下代码在Mozilla Firefox、Internet Explorer中运行正常,但在谷歌Chrome中出现上述错误。

管理登录.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>

结构配置.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>

用户操作.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.
uhry853o

uhry853o1#

我认为由于您没有在URL中提到参数'method',您将得到错误。我不确定IE和FF是如何工作的,但如果您构建类似UsrAction.do?method=lodable的URL,我相信它在chrome中也应该工作。

bihw5rsg

bihw5rsg2#

出现异常的原因是您在Struts配置文件中添加了一个参数parameter="method",系统现在正在该变量中查找方法名,而您在代码中没有提供该变量。
您应该使用hidden from属性来提供方法名称,以避免例外状况。

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

希望这能帮助到一些人,

7d7tgy0s

7d7tgy0s3#

由于Javascript错误,我也遇到过同样的问题,在来自action类的FormBean中,我放置了一个新变量,但没有将其放置到from中,然后我尝试从表单中获取它,如

document.forms[0].VARIABLE_NAME.value

因为此变量不存在于表单中,但存在于FormBean中,所以JS无法找到它,并且无法正确提交表单。
因此,为了解决这个问题,我使用了隐藏的表单字段,并将新变量放在表单中,然后从那里使用它。修复了我的问题。

相关问题