2014-04-27 3 views
0

나는 JSP로 새로운 JSP 페이지를 처음 만들었습니다. 여기서는 사용자가 지정한 값을 낮은 텍스트 상자에 표시하도록 설정하려고합니다. 그러나 제출 후에도 null 값만 취합니다. 내 코드는 다음과 같습니다.왜 POST 매개 변수에 값이 적용되지 않습니까?

<form action="index.jsp" method="post"> 
      <table> 
       <tr> 
        <td>Country</td> 
        <td><input id="countryText" type="text" > </td> 
       </tr> 
       <tr> 
        <td>City</td> 
        <td><input id="cityText" type="text" ></td> 
       </tr> 
       <tr> 
        <td>Check in Date</td> 
        <td><input id="checkinText" type="text" ></td> 
       </tr> 
       <tr> 
        <td>No of Nights</td> 
        <td><input id="noOfNightsText" type="text" ></td> 
       </tr> 
       <tr> 
        <td>No of Rooms</td> 
        <td><input id="noOfRoomsText" value="1" type="text" disabled></td> 
       </tr> 
       <tr> 
        <td></td> 
        <td align="right"><button id="searchButton" type="submit" class="buttonClass">Search Hotels</button></td> 
       </tr> 
      </table> 
     </form> 

     <table> 
      <tr> 
       <td>Country</td> 
       <td><input id="countryTextOutput" value="<%= request.getParameter("countryText")%>" type="text" disabled> </td> 
      </tr> 
      <tr> 
       <td>City</td> 
       <td><input id="cityTextOutput" value="<%= request.getParameter("cityText")%>" type="text" disabled></td> 
      </tr> 
      <tr> 
       <td>Check in Date</td> 
       <td><input id="checkinTextOutput" value="<%= request.getParameter("checkinText")%>" type="text" disabled></td> 
      </tr> 
      <tr> 
       <td>No of Nights</td> 
       <td><input id="noOfNightsTextOutput" value="<%= request.getParameter("noOfNightsText")%>" type="text" disabled></td> 
      </tr> 
      <tr> 
       <td>No of Rooms</td> 
       <td><input id="noOfRoomsTextOutput" value="<%= request.getParameter("noOfRoomsText")%>" type="text" disabled></td> 
      </tr> 
     </table> 

내 웹 인터페이스 Web Interface

미리 감사드립니다 ..!

+2

또한 입력에 이름 속성을 추가하십시오. – thexacre

+0

@mit : 답이되어야합니다 (조금 더 정교한 경우). –

+0

그것은 작동합니다. 고마워 많이 mit : :) –

답변

2

당신은 예를 들어, 입력 필드에 이름 속성을 추가해야합니다

<input id="countryText" type="text" > 

이 될해야 :

<input id="countryText" name="countryText" type="text" > 

은 또한 당신의 필드가 폼 내부에 있는지 확인하십시오.

0

request.getParameter은 input 요소의 name 속성을 사용합니다. 여기에 이드를 주셨습니다. 입력 요소에 이름 속성을 추가해보세요.

<table> 
       <tr> 
        <td>Country</td> 
        <td><input name="countryText" type="text" > </td> 
       </tr> 
       <tr> 
        <td>City</td> 
        <td><input name="cityText" type="text" ></td> 
       </tr> 
       <tr> 
        <td>Check in Date</td> 
        <td><input name="checkinText" type="text" ></td> 
       </tr> 
       <tr> 
        <td>No of Nights</td> 
        <td><input name="noOfNightsText" type="text" ></td> 
       </tr> 
       <tr> 
        <td>No of Rooms</td> 
        <td><input name="noOfRoomsText" value="1" type="text" disabled></td> 
       </tr> 
       <tr> 
        <td></td> 
        <td align="right"><button id="searchButton" type="submit" class="buttonClass">Search Hotels</button></td> 
       </tr> 
      </table> 
0

필드의 값을 얻으려면 이름이 필요하지 않습니다.

그래서 이름 속성을 사용하고 내부에 그 이름을 전달하여 request.getParameter(name)

이 같은 귀하의 ID와 이름을 넣어 빠른 솔루션에 대한 문제 100 %

를 해결할

. 디스플레이에서 아무 것도 변경할 필요가 없습니다.

+0

안녕하세요 @ 킬로바이트, 둘 다 동시에 대답 하 ... 하 !! :) –

+0

안녕하세요 Ramesh .. 우연의 일치 우스운 ... –

관련 문제