秀和システムのspringFrameWork4 プログラミング入門のP201、図4-23のフォームを送信すると、その内容がMyBeanに追加されるところで404になってしまい手が止まっています。ご教授いただけると幸いです。
###発生している問題・エラーメッセージ
エラーメッセージ
package jp.tuyano.spring.websample1;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
- Servlet implementation class MySampleServlet
*/
public class MySampleServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
ApplicationContext app; /** * @see Servlet#init(ServletConfig) */ public void init(ServletConfig config) throws ServletException { super.init(); app =new ClassPathXmlApplicationContext("/spring/application-config.xml"); } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { MyBean mybean1 =(MyBean)app.getBean("mybean1"); request.setAttribute("mybean", mybean1); request.getRequestDispatcher("sample").forward(request, response); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String message =request.getParameter("message"); MyBean mybean1 =(MyBean)app.getBean("mybean1"); mybean1.addMessage(message); response.sendRedirect("/index.jsp"); }
}
<!DOCTYPE html><%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
Web.xmlの記述
<?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>MySampleWebApp1</display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/application-config.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <description></description> <display-name>MySampleServlet</display-name> <servlet-name>MySampleServlet</servlet-name> <servlet-class>jp.tuyano.spring.websample1.MySampleServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>MySampleServlet</servlet-name> <url-pattern>/Sample</url-pattern> </servlet-mapping> </web-app>このように本に記載されているコードに忠実に習ったのですがsendRedirectがうまくいきません。
###補足情報(言語/FW/ツール等のバージョンなど)
より詳細な情報
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/28 15:58