source: http://stackoverflow.com/questions/5177749/where-are-doget-and-dopost-methods-in-the-servlets-translated-from-jsps
Question:
In the Servlets that are translated from jsps , I notice that there is
Answer:
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html;charset=euc-kr">
<TITLE>이름 입력</TITLE>
</HEAD>
<BODY>
당신의 이름을 입력하십시오.
<FORM ACTION=/brain03/Hi.jsp METHOD=GET>
이름: <INPUT TYPE=TEXT NAME=YOURNAME>
<INPUT TYPE=SUBMIT VALUE='확인'>
</FORM>
</BODY>
</HTML>
<%@page contentType="text/html; charset=euc-kr"%>
<HTML>
<HEAD><TITLE>인사하기</TITLE></HEAD>
<BODY>
안녕하세요, <%= request.getParameter("YOURNAME") %>님
</BODY>
</HTML>
* Generated by the Jasper component of Apache Tomcat
* Version: Apache Tomcat/7.0.26
* Generated at: 2013-09-10 04:48:24 UTC
* Note: The last modified time of this file was set to
* the last modified time of the source file after
* generation to assist with modification tracking.
*/
package org.apache.jsp;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
public final class Hi_jsp extends org.apache.jasper.runtime.HttpJspBase
implements org.apache.jasper.runtime.JspSourceDependent {
private static final javax.servlet.jsp.JspFactory _jspxFactory =
javax.servlet.jsp.JspFactory.getDefaultFactory();
private static java.util.Map<java.lang.String,java.lang.Long> _jspx_dependants;
private javax.el.ExpressionFactory _el_expressionfactory;
private org.apache.tomcat.InstanceManager _jsp_instancemanager;
public java.util.Map<java.lang.String,java.lang.Long> getDependants() {
return _jspx_dependants;
}
public void _jspInit() {
_el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
_jsp_instancemanager = org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(getServletConfig());
}
public void _jspDestroy() {
}
public void _jspService(final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response)
throws java.io.IOException, javax.servlet.ServletException {
final javax.servlet.jsp.PageContext pageContext;
javax.servlet.http.HttpSession session = null;
final javax.servlet.ServletContext application;
final javax.servlet.ServletConfig config;
javax.servlet.jsp.JspWriter out = null;
final java.lang.Object page = this;
javax.servlet.jsp.JspWriter _jspx_out = null;
javax.servlet.jsp.PageContext _jspx_page_context = null;
try {
response.setContentType("text/html; charset=euc-kr");
pageContext = _jspxFactory.getPageContext(this, request, response,
null, true, 8192, true);
_jspx_page_context = pageContext;
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
_jspx_out = out;
out.write("\r\n");
out.write("<HTML>\r\n");
out.write(" <HEAD><TITLE>인사하기</TITLE></HEAD>\r\n");
out.write(" <BODY>\r\n");
out.write(" 안녕하세요, ");
out.print( request.getParameter("YOURNAME") );
out.write("님\r\n");
out.write(" </BODY>\r\n");
out.write("</HTML>\r\n");
out.write("\r\n");
out.write("\r\n");
} catch (java.lang.Throwable t) {
if (!(t instanceof javax.servlet.jsp.SkipPageException)){
out = _jspx_out;
if (out != null && out.getBufferSize() != 0)
try { out.clearBuffer(); } catch (java.io.IOException e) {}
if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
}
} finally {
_jspxFactory.releasePageContext(_jspx_page_context);
}
}
}
Question:
In the Servlets that are translated from jsps , I notice that there is
_jspservice()
method but nodoGet()
and doPost()
methods ? how does the servlet differentiate the GET
and the POST
methods ?Answer:
There is no real difference in handling of
GET
and POST
requests in JSP. If you are interested in what method was used, you can call getMethod()
to find out.
The way JSPs work is the same as if you overrode
service(ServletRequest, ServletResponse)
in a Servlet instead of doGet
/ doPost
.
(예제)
1. 이름을 입력받는 간단한 YourName.html 파일이며, 이를 Get방식으로 아래의 Hi.jsp파일로 폼내용을 전송함.
YourName.html 화면 |
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html;charset=euc-kr">
<TITLE>이름 입력</TITLE>
</HEAD>
<BODY>
당신의 이름을 입력하십시오.
<FORM ACTION=/brain03/Hi.jsp METHOD=GET>
이름: <INPUT TYPE=TEXT NAME=YOURNAME>
<INPUT TYPE=SUBMIT VALUE='확인'>
</FORM>
</BODY>
</HTML>
2. Hi.jsp 파일과 결과는 다음과 같다.
Hi.jsp의 화면 |
<HTML>
<HEAD><TITLE>인사하기</TITLE></HEAD>
<BODY>
안녕하세요, <%= request.getParameter("YOURNAME") %>님
</BODY>
</HTML>
3. Hi_jsp.java (Hi.jsp 파일이 톰켓 컨테이너에 의해 변환된 서블릿 클래스 코드)
/** Generated by the Jasper component of Apache Tomcat
* Version: Apache Tomcat/7.0.26
* Generated at: 2013-09-10 04:48:24 UTC
* Note: The last modified time of this file was set to
* the last modified time of the source file after
* generation to assist with modification tracking.
*/
package org.apache.jsp;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
public final class Hi_jsp extends org.apache.jasper.runtime.HttpJspBase
implements org.apache.jasper.runtime.JspSourceDependent {
private static final javax.servlet.jsp.JspFactory _jspxFactory =
javax.servlet.jsp.JspFactory.getDefaultFactory();
private static java.util.Map<java.lang.String,java.lang.Long> _jspx_dependants;
private javax.el.ExpressionFactory _el_expressionfactory;
private org.apache.tomcat.InstanceManager _jsp_instancemanager;
public java.util.Map<java.lang.String,java.lang.Long> getDependants() {
return _jspx_dependants;
}
public void _jspInit() {
_el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
_jsp_instancemanager = org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(getServletConfig());
}
public void _jspDestroy() {
}
public void _jspService(final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response)
throws java.io.IOException, javax.servlet.ServletException {
final javax.servlet.jsp.PageContext pageContext;
javax.servlet.http.HttpSession session = null;
final javax.servlet.ServletContext application;
final javax.servlet.ServletConfig config;
javax.servlet.jsp.JspWriter out = null;
final java.lang.Object page = this;
javax.servlet.jsp.JspWriter _jspx_out = null;
javax.servlet.jsp.PageContext _jspx_page_context = null;
try {
response.setContentType("text/html; charset=euc-kr");
pageContext = _jspxFactory.getPageContext(this, request, response,
null, true, 8192, true);
_jspx_page_context = pageContext;
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
_jspx_out = out;
out.write("\r\n");
out.write("<HTML>\r\n");
out.write(" <HEAD><TITLE>인사하기</TITLE></HEAD>\r\n");
out.write(" <BODY>\r\n");
out.write(" 안녕하세요, ");
out.print( request.getParameter("YOURNAME") );
out.write("님\r\n");
out.write(" </BODY>\r\n");
out.write("</HTML>\r\n");
out.write("\r\n");
out.write("\r\n");
} catch (java.lang.Throwable t) {
if (!(t instanceof javax.servlet.jsp.SkipPageException)){
out = _jspx_out;
if (out != null && out.getBufferSize() != 0)
try { out.clearBuffer(); } catch (java.io.IOException e) {}
if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
}
} finally {
_jspxFactory.releasePageContext(_jspx_page_context);
}
}
}
댓글
댓글 쓰기