プロが教える店舗&オフィスのセキュリティ対策術

今回、eclipseで開発をすることになりました。
しかしながら、動的Webプロジェクトという使い慣れないプロジェクトでの作成を
しなくてはならなくなり、混乱しています。

tomcatとWTPのことについては、先の質問で教えて頂き解決したのですが、
もう一つ困ったことがあったので、再度質問させて頂きます。

---------------------------------------
環境
Windows7 Ultimate
eclipse Indigo
tomcat 5.5
---------------------------------------

まずは、JSPを作成し、それを実行し、ブラウザ上に表示することは出来ました。
その後にServletに<form action ="/test" method = "POST">という形で投げるのですが、
それがうまくいかず、404エラーが出てしまいます。

階層としては、JSPはSample(プロジェクト名)/WebContent/NewFile.jspに配置しています。
そして、Servletについては、Sample(プロジェクト名)/src/test/Test.javaに配置しています。
web.xmlについては、Sample(プロジェクト名)/WebContent/WEB-INF/web.xmlにあります。

まず、JSPのソースは以下の様に書かれています。
-----------------------------------------------------
<%@ page contentType="text/html;charset=Windows-31J" language="java"%>
<%@ page pageEncoding="Windows-31J"%>

<html>
<head><title>タイトル</title></head>


<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<%request.setCharacterEncoding("Windows-31J");%>

<body>
<form method="POST" action="/test">
<%--ここに処理を記述 --%>
<input type = "submit" name="submit" value = "送信">
</form>

</body>
</html>
-----------------------------------------------------

Servletについては、以下の様に、型だけ記述しています。

-----------------------------------------------------
package test;


import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class Test
*/
public class Test extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public Test() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}

}
----------------------------------------------------

そして、web.xmlについては、以下の様に記述しています。
----------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>SampleWeb</display-name>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>

<servlet>
<servlet-name>test</servlet-name>
<servlet-class>test.Test</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>

</web-app>
-----------------------------------------------------

その状態で、JSPの中から
<form action ="/test" method = "POST">
<input type ="submit" name = "submit" value="送信">
</form>

とやっても、404が出てしまいます。

Java自体が久々で、根本的に間違っているかもしれませんが、
ご教授お願い致します。

A 回答 (1件)

# <form method="POST" action="/test">





<form method="POST" action="./test">

<form method="POST" action="test">
    • good
    • 0
この回答へのお礼

ありがとうございますっ!

ものすごく目から鱗が落ちました☆

お礼日時:2012/06/14 17:50

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!

このQ&Aを見た人はこんなQ&Aも見ています