java 请求 [/UsrAction] 不包含名为“方法”的处理程序参数。这可能是由标签文本中的空格引起的

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17318013/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-01 01:40:31  来源:igfitidea点击:

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

javajspstrutsstruts-1

提问by Code Hungry

Below Code is working fine in Mozila Firefox, Internet Explorer but giving above error in google chrome.

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

adminlogin.jsp

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

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);
}
}

Error Log

错误日志

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.

回答by real gadha

I think as you have not mentioned the parameter 'method' in the URL, you are getting the error. I am not sure how IE and FF is working, but if you construct the URL something like UsrAction.do?method=lodableI believe, it should work in chrome as well.

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

回答by NoNaMe

The reason of the exception is that you have added a param parameter="method"in your Struts config file and system is now looking for method name in that variable which is not supplied by you in the code.

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

You should use hidden from property to provide the method name to avoid the exception.

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

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

Hope this will help someone,

希望这会帮助某人,