主题:求教高手,帮我看看这段代码
package webdemo1;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class MyServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//初始化全局变量
public void init() throws ServletException {
}
//处理 HTTP 请求
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE);
response.setCharacterEncoding("GB2312");
PrintWriter out = response.getWriter();
try{
String userName = request.getParameter("username");
String Password = request.getParameter("password");
if(userName.equals(" ")||Password.equals(" "))
{
userInterface(response);
}
else
{
out.println("<b>" + userName +"</b> 欢迎第一次使用Servlet <br/>");
out.println("<b>今天的日期是:</b>" + new Date());
}
}
catch(Exception e){
userInterface(response);
}
out.close();
}
public void userInterface(HttpServletResponse response)throws
IOException{
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>欢迎使用Servlet!</title></head>");
out.println("<body bgcolor = \" #ffffff \">");
out.println("<h1 align = center>欢迎第一次使用Servlet</h1>");
out.println("<form method=post action=/WebModule1/MyServlet>");
out.println("<br/>");
out.println("用户名:<input type='text' name='username'><br/>");
out.println("密码:<input type='password' name='password'><br/>");
out.println("<input type=submit value='提交'><br/>");
out.println("</form>");
out.println("</body>");
out.println("</html>");
}
//处理 HTTP Post 请求
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}
//清除资源
public void destroy() {
}
private void jbInit() throws Exception {
}
}
应该是填完登陆页面显示用户名,为什么总是出错?望高手指教!!不胜感激!!
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class MyServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//初始化全局变量
public void init() throws ServletException {
}
//处理 HTTP 请求
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE);
response.setCharacterEncoding("GB2312");
PrintWriter out = response.getWriter();
try{
String userName = request.getParameter("username");
String Password = request.getParameter("password");
if(userName.equals(" ")||Password.equals(" "))
{
userInterface(response);
}
else
{
out.println("<b>" + userName +"</b> 欢迎第一次使用Servlet <br/>");
out.println("<b>今天的日期是:</b>" + new Date());
}
}
catch(Exception e){
userInterface(response);
}
out.close();
}
public void userInterface(HttpServletResponse response)throws
IOException{
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>欢迎使用Servlet!</title></head>");
out.println("<body bgcolor = \" #ffffff \">");
out.println("<h1 align = center>欢迎第一次使用Servlet</h1>");
out.println("<form method=post action=/WebModule1/MyServlet>");
out.println("<br/>");
out.println("用户名:<input type='text' name='username'><br/>");
out.println("密码:<input type='password' name='password'><br/>");
out.println("<input type=submit value='提交'><br/>");
out.println("</form>");
out.println("</body>");
out.println("</html>");
}
//处理 HTTP Post 请求
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}
//清除资源
public void destroy() {
}
private void jbInit() throws Exception {
}
}
应该是填完登陆页面显示用户名,为什么总是出错?望高手指教!!不胜感激!!