0
서블릿을 사용하여 간단한 웹 응용 프로그램을 작성하려고했습니다. 프리스트 페이지를 실행하려고하면 URL "//localhost:8080/PassingParameter/ParamHtml.html"로 올바르게 실행됩니다. 내 서블릿 코드에서 이 가 보호 무효의 doGet (HttpServletRequest 요청, HttpServletResponse 응답) XML 코드가@WebServlet annotation with tomcat 6
입니다ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html");
PrintWriter out=response.getWriter();
String title = "Reading All Form Parameters";
String docType =
"<!doctype html public \"-//w3c//dtd html 4.0 " +
"transitional//en\">\n";
out.println(docType +
"<html>\n" +
"<head><title>" + title + "</title></head>\n" +
"<body bgcolor=\"#f0f0f0\">\n" +
"<h1 align=\"center\">" + title + "</h1>\n" +
"<table width=\"100%\" border=\"1\" align=\"center\">\n" +
"<tr bgcolor=\"#949494\">\n" +
"<th>Param Name</th><th>Param Value(s)</th>\n"+
"</tr>\n");
Enumeration<?> paramNames = request.getParameterNames();
while(paramNames.hasMoreElements()) {
String paramName = (String)paramNames.nextElement();
out.print("<tr><td>" + paramName + "</td>\n<td>");
String[] paramValues =
request.getParameterValues(paramName);
// Read single valued data
if (paramValues.length == 1) {
String paramValue = paramValues[0];
if (paramValue.length() == 0)
out.println("<i>No Value</i>");
else
out.println(paramValue);
} else {
// Read multiple valued data
out.println("<ul>");
for(int i=0; i < paramValues.length; i++) {
out.println("<li>" + paramValues[i]);
}
out.println("</ul>");
}
}
out.println("</tr>\n</table>\n</body></html>");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
던졌습니다 : 나는 다음 버튼을 클릭하면 URL은 "8080/ReadParamUrl/* 로컬 호스트는"너무 변화
<welcome-file>ParamHtml.html</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>ReadParam</display-name>
<servlet-name>ReadParam</servlet-name>
<servlet-class>org.param.ReadParam</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ReadParam</servlet-name>
<url-pattern>/ReadParamUrl</url-pattern>
</servlet-mapping>
HTML 코드는 내가 URL이 올바른 준 희망
<form action="/ReadParamUrl" method="POST" target="_blank">
<input type="checkbox" name="maths" checked="checked" /> Maths
<input type="checkbox" name="physics" /> Physics
<input type="checkbox" name="chemistry" checked="checked" /> Chemistery
<input type="submit" value="Select Subject" />
</form>
이지만, 그것은 작동하지 않습니다. 도와주세요.