有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

JavaETATHTTP404/mvc/traitementTwo。jsp spring mvc

我试图将表单中输入的名称大写并显示出来

控制员:

package yo;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HelloWorldController {

    @RequestMapping("/")
    public String showPage(){
        return "helloworld";
       }

    @RequestMapping("/showForm")
    public String showForm(){
        return"form";
    }
    @RequestMapping("/traitement")
    public String processForm(){
        return"traitement";
    }
    @RequestMapping("/traitementTwo")
    public String caps(HttpServletRequest request,Model model){

        String theName=request.getParameter("s");
        String result="YO "+theName.toUpperCase();
        model.addAttribute("message", result);
        return"helloworld";
    }

}

形式。jsp:

<body>
hello   <form action="traitementTwo.jsp" method="GET">

    <input type="text" name="s" placeholder="who are u ?" />

    <input type="submit"/>

    </form>

</body>
</html>

地狱世界。jsp:

<html>
<body>
    the time on the server is <%= new String("Hello World").toUpperCase() %>
<br>


    The message :${message}

</body>
</html>

spring mvcdemo servlet:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <!-- Step 3: Add support for component scanning -->
    <context:component-scan base-package="yo" />

    <!-- Step 4: Add support for conversion, formatting and validation support -->
    <mvc:annotation-driven/>

    <!-- Step 5: Define Spring MVC view resolver -->
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/view/" />
        <property name="suffix" value=".jsp" />
    </bean>

</beans>

网络。xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    id="WebApp_ID" version="3.1">

    <display-name>mvc</display-name>

    <!-- Spring MVC Configs -->

    <!-- Step 1: Configure Spring MVC Dispatcher Servlet -->
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring-mvc-demo-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- Step 2: Set up URL mapping for Spring MVC Dispatcher Servlet -->
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

输出:

etathttp404-/mvc/traitementTwo。jsp 键入融洽关系détat

message/mvc/traitementTwo。jsp

说明资源需求不存在争议


ApacheTomcat/8.0.36


共 (3) 个答案

  1. # 1 楼答案

    好的,我想我知道问题是什么。。以你的形式。您有:

    <form action="traitementTwo.jsp" method="GET">
    

    应该是:

    <form action="traitementTwo" method="GET">
    
  2. # 2 楼答案

    您已经使用SpringMVC进行开发,但没有SpringMVC配置XML文件。您应该创建一个SpringMVC。xml来配置有关SpringMVC的一些消息

  3. # 3 楼答案

    听起来你可能没有设置你的网站。正确使用xml来创建servlet上下文等

    请参阅以下项目:https://www.mkyong.com/spring-mvc/spring-mvc-and-list-example/

    它在src中具有以下结构->;主要->;网络应用

    /-网络。xml

    /-mvc调度程序servlet。xml

    /pages(存储jsp页面的目录)

    否则,请发布您的webapp或spring引导配置,以确认您已正确设置