Forms 无法返回到所需的JSP URL或视图

Forms 无法返回到所需的JSP URL或视图,forms,jsp,spring-mvc,Forms,Jsp,Spring Mvc,所以它应该像这样打开 C:\Users\ganganshu.s\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5\YW6383E8\usermaster http://localhost:8080/enbee/usermaster 你能告诉我我应该在行动表上写些什么吗。。因为我认为在SpringMVC中动作的形式中有一些错误,我们把动作放在上面提到的例子中 http://localhost:8080/en

所以它应该像这样打开

C:\Users\ganganshu.s\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5\YW6383E8\usermaster
http://localhost:8080/enbee/usermaster
你能告诉我我应该在行动表上写些什么吗。。因为我认为在SpringMVC中动作的形式中有一些错误,我们把动作放在上面提到的例子中

http://localhost:8080/enbee/usermaster
Spring confg文件如下所示:

http://localhost:8080/enbee/usermaster

http://localhost:8080/enbee/usermaster

jsp名称为usermaster.jsp

http://localhost:8080/enbee/usermaster
在sidemenu.jsp中,我改为:

http://localhost:8080/enbee/usermaster
<!-- Declare a view resolver-->
<bean id="jspViewResolver"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver"
    p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" p:order="1" />

  • RequestMapping
    注释的
    method
    参数更改为
    RequestMethod。POST

    http://localhost:8080/enbee/usermaster
    
     <li><a href="<c:url value='/showusermaster'/>">User Master</a></li>
    
    因此,当您使用
    method=“POST”
    将表单提交到URL
    /usermaster
    时,将执行此方法

    http://localhost:8080/enbee/usermaster
    
    您还需要有一个向用户显示此页面的方法(映射到URL)。为此,您可以使用以下方法:

    http://localhost:8080/enbee/usermaster
    
    @RequestMapping(value="/usermaster", method = RequestMethod.POST)
    public final String addUserMaster(...){
    ...
    }
    
    使用此方法后,URL

    http://localhost:8080/enbee/usermaster
    
    @RequestMapping(value = "/showusermaster", method = RequestMethod.GET)
    public String showPage(ModelMap model){
    model.addAttribute("CustomerForm", new CustomerForm());
    return "usermaster";
    } 
    
    将向用户显示
    usermaster.jsp
    页面。现在,当您提交此
    表单时,将调用上述
    addUserMaster
    方法

    http://localhost:8080/enbee/usermaster
    
    您不必创建新的jsp文件。url
    /showusermaster
    将向用户返回
    usermaster.jsp
    ,用户可以在其中添加表单值并提交表单:

    http://localhost:8080/enbee/usermaster
    
    http://localhost:8080/enbee/showusermaster
    
    
    ...
    

    现在,当用户单击submit按钮时,此表单将被提交到
    /usermaster
    URL,并由
    addUserMaster
    方法处理。

    尝试指定控制器方法返回的内容类型,添加
    products=“text/html”
    将参数添加到您的
    @RequestMapping
    注释中。

    请正确设置问题的格式,并尝试提供一个最小的示例(即,不要发布与问题无关的代码)。您现在能理解我的问题吗?请发布您的Spring配置文件。表单所在的文件名是什么?你能打开
    http://localhost:8080/enbee/usermaster
    ?如果是,结果是什么?还请详细说明错误发生的时间和方式。如果我试图打开它,则会说“您想从localhost打开还是保存”是/否如果我单击“是”,它会说你想通过哪个程序打开它,然后我会选择IE。此时,它会从链接c://…usermaster打开它。我收到消息“请求方法“GET”不受支持”如果我添加RequestMethod.GET,那么同样的问题仍然存在。那么我是否需要创建一个名为showusermaster的新jsp,或者我必须如何将showusermaster映射到jsp。请您解释一下。我需要在jsp中做哪些更改请您解释一下。您是正确的。。。但是我得到的是HTTP:Status 505 Get方法不受支持。仍然会遇到相同的问题。如果在
    @ResponseBody
    注释的正下方添加
    @RequestMapping
    ,会发生什么情况?此注释意味着您从函数返回的字符串应解释为响应,而不是解释为视图名称。它仅打印字符串usermaster onlyok,这是预期的。这意味着如何解析视图名称存在问题。我建议遵循@Debojit Saikia的答案,我也会这样做。
    http://localhost:8080/enbee/usermaster