Base-Jsp-12-Jsp翻译为servlet

王朝java/jsp·作者佚名  2006-02-01
窄屏简体版  字體: |||超大  

ª 事例:

<%@ page language=”java” contentType=”text/html”%>

<%@ page import=”java.util.Date”%>

<%!

Private String getGreeting()

{

Date now = new Date();

String greeting = null;

If( now.getHours()<12)

{

greeting = “Good morning”;

}

else if(now.getHours()<18)

{

gretting = “Good day”;

}

else

{

greeting = “good evening”;

}

Return greeting;

}

%>

<html>

<head>

<title>All Scripting Elements</title>

</head>

<body bgcolor=”white”>

<%=ge tGreeting()%>

<%if (request.g etParameter(“name”) = = null) {%>

Stranger!

<%} else {%>

Partner

<%}%>

How are you?

</body>

</html>

ª 转化后的servlet

import java.util.Date;

import javax.servlet.*;

import javax.servlet.http.*;

import javax.servlet.jsp.*;

public class allinone$jsp extends HttpJspBase

{

//声明元素原封不动的插入到了类的顶级

//声明元素中的方法没有访问JSP隐式变量的权限,如果要访问,必须作为参数传给该方法

Private String getGreeting()

{

Date now = new Date();

String greeting = null;

If( now.getHours()<12)

{

greeting = “Good morning”;

}

else if(now.getHours()<18)

{

gretting = “Good day”;

}

else

{

greeting = “good evening”;

}

return greeting;

}

public void _jspService(HttpServletRequest request,

HttpServletResponse response)

throws java.io.IOException,ServletException

{

//JSP隐含变量都是局部变量

JspFactory _jspxFactory = null;

PageCOntext pageCOntext = null;

HttpSession session = null;

ServletContext application = null;

ServletConfig config = null;

JspWriter out = null;

Object page = this;

String _value = null;

try

{

_jspFactory = JspFactory.getDefaultFactory();

response.setContentType("text/html");

pageContext =

_jspxFactory.getPageContext(this,request,response,

"",true,8129,true);

application =pageContext.getServletContext();

config = pageContext.getServletConfig()l

session =pageContext.getSession();

out = pageContext.getOut();

out.write("\r\n");

out.write("\r\n");

out.write("\r\n<html>\r\n<head>\r\n");

out.write("<title>all scription Elements<title>\r\n");

out.write("<\head>\r\n<body bgcolor=\"white\">\r\n");

//表达式元素也原封不动的插入,所以不应该在JSP表达式末尾使用分号的原因

out.print(getGreeting());

out.write("\r\n");

if(request.getParameter("name") ==null)

{

out.write("\r\n stranger! \r\n");

}

else

{

out.write("\r\n partner! \r\n");

}

out.write("\r\n How are you? \r\n");

out.write("</body>\r\n</html>\r\n");

}

catch(Throwable t)

{

if(out !== null & out.getBufferSize() !=0)

{

out.clearBuffer();

}

if(pageContext != null)

{

pageContext.handlePageException(t);

}

}

finally

{

if(_jspxFactory != null)

_jspxFactory.releasePageCOntext(pageContext);

}

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航