马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
Java伴随着互联网的迅猛发展而发展,逐渐成为重要的网络编程语言。Oracle收购Sun后Java前途未卜。servlet/*
何志强[hhzqq@21cn.com]
日期:2000-08-10
版本:1.0
功效:Servlet基本例程-HelloServlet
*/
importjava.io.*;
importjava.text.*;//MessageFormat
importjavax.servlet.*;
importjavax.servlet.http.*;
publicclassHelloServletextendsHttpServlet{
//页面题目
protectedstaticfinalStringstrTitle="Servlet基本例程-HelloServlet";
//页眉
protectedstaticfinalStringstrHeader=
"<html>"+
"<head>"+
"<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">"+
"<title>{0}</title>"+
"</head>"+
"<body>";
//页脚
protectedstaticfinalStringstrFooter=
"</body>"+
"</html>";
//表单
protectedstaticfinalStringstrForm=
"<formaction="{0}"method="post">"+
"您贵姓台甫:<inputtype="text"name="name">"+
"<inputtype="submit"name="submit"value="提交">"+
"</form>";
protectedstaticfinalStringstrHello=
"您好,{0},接待离开Servlet/JSP天下!";
//堕落信息
protectedstaticfinalStringstrError=
"<h2><fontcolor="#ff0000">{0}</font></h2>";
protectedvoiddoGet(HttpServletRequestreq,HttpServletResponseresp)throwsServletException,IOException{
process(req,resp);
}
protectedvoiddoPost(HttpServletRequestreq,HttpServletResponseresp)throwsServletException,IOException{
process(req,resp);
}
protectedvoidprocess(HttpServletRequestreq,HttpServletResponseresp)throwsServletException,IOException{
try{
Stringsubmit=req.getParameter("submit");
if(submit==null)
printForm(req,resp);
else
printHello(req,resp);
}
catch(Exceptione){
printError(e.toString(),req,resp);
}
}
protectedvoidprintForm(HttpServletRequestreq,HttpServletResponseresp)throwsServletException,IOException{
//在利用PrintWriter前得先设置ContentType
resp.setContentType("text/html");
PrintWriterout=resp.getWriter();
//输入页眉
out.print(MessageFormat.format(strHeader,newObject[]{strTitle+"-请输出贵姓台甫"}));
//输入表单
out.print(MessageFormat.format(strForm,newObject[]{req.getContextPath()+req.getServletPath()}));
//输入页脚
out.print(strFooter);
out.flush();
}
protectedvoidprintHello(HttpServletRequestreq,HttpServletResponseresp)throwsServletException,IOException{
//猎取用户输出的数据
Stringname=req.getParameter("name");
if(name==null)
name="知名氏";
//在利用PrintWriter前得先设置ContentType
resp.setContentType("text/html");
PrintWriterout=resp.getWriter();
//输入页眉
out.print(MessageFormat.format(strHeader,newObject[]{strTitle+"-接待您"}));
//输入接待信息
out.print(MessageFormat.format(strHello,newObject[]{name}));
//输入页脚
out.print(strFooter);
out.flush();
}
protectedvoidprintError(Stringerror,HttpServletRequestreq,HttpServletResponseresp)throwsServletException,IOException{
//在利用PrintWriter前得先设置ContentType
resp.setContentType("text/html");
PrintWriterout=resp.getWriter();
//输入页眉
out.print(MessageFormat.format(strHeader,newObject[]{strTitle+"-堕落信息"}));
//输入堕落信息
out.print(MessageFormat.format(strError,newObject[]{error}));
//输入页脚
out.print(strFooter);
out.flush();
}
}
市场分额,java比asp高一点,因为C#是仿照java开发的,所以哦C#能做的java都能做到,但是java能做的,C#不一定都能做到。毕竟是抄袭吗。 |