2013-11-28 2 views
0

내가 기본 HTML 양식을 서블릿에 제출HTML 양식 오류가 서블릿에 POST 요청을 제출하는 같이

그리고 나는 URL을 사용하여 제출 http://localhost:8080/sample/forms.html

그러나이 요청을 제출할 때

http://localhost:8080/getFormParam 

사용되는 형식은 다음과 같습니다 :

<form method="post" action="/getFormParam"> 
<input type="text" name="user" /> 
<input type="text" name="id"/> 
<input type="submit" value="Submit"/> 
<input type="reset" value="clear"/> 
</form> 
,691으로 컨텍스트 루트 부분은 삭제됩니다 및 URL이 보인다

은 web.xml 매핑은 문제가 여기에 무엇

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> 
<web-app> 
    <servlet> 
     <servlet-name>getFormParam</servlet-name> 
     <servlet-class>dep.getFormParam</servlet-class> 
     </servlet> 
     <servlet-mapping> 
     <servlet-name>getFormParam</servlet-name> 
     <url-pattern>/getFormParam</url-pattern> 
     </servlet-mapping> 
     </web-app> 

입니다.

답변

1

문제는 "/"는 액션 매개 변수에

<form method="post" action="/getFormParam">

당신이 URL의 앞에 슬래시를 언급, 그것은 자원의 컨텍스트 루트에있는 것을 의미 단지 앞 슬래시 이 경우에는 localhost : 8080 인 tomcat 서버 (응용 프로그램의 컨텍스트 루트가 아님). 당신이

<form method="post" action="getFormParam">

로 변경하면 당신이 원하는처럼 작동하기 시작합니다. 어쨌든이 상황에 다시 갇히지 않는 경우를 대비하여 URL 재 작성 개념을 알고있는 것이 가장 좋습니다.이 상황을 극복하기 위해 JSTL 라이브러리 내에 url이라는 이름의 태그가 있습니다. URL을 전달하면 항상 응용 프로그램의 컨텍스트 루트 (URL 다시 쓰기)로 확인됩니다.

자세한 내용은 찾을 수 있습니다. here

1

문제는

<form method="post" action="/getFormParam"> 

변경에 그것입니다 포스트 URL은 서블릿이 요청을 지금 얻을 것이다 http://localhost:8080/sample/getFormParam 될 것

<form method="post" action="getFormParam"> 

(/ 제거).

관련 문제