急求关于Servlet的一个问题
我是用JBuilder2006做了一个简单的Serlet的程序
可是出现了一个问题,就是第一个页面出来了,可是点提交后,就没有反映了,希望大家能帮我看看,下面是代码:
package example1;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
/**
* <p> Title: </p>
*
* <p> Description: </p>
*
* <p> Copyright: Copyright (c) 2007 </p>
*
* <p> Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class LoginServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK ";
//初始化全局变量
public void init() throws ServletException {
}
//处理HTTP Get 请求
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> LoginServlet </title> </head> ");
out.println( " <body bgcolor=\ "#ffffff\ "> ");
out.println( " <h1 align=center> 欢迎第一次使用Servler </h1> ");
out.println( " <fron method=post action=/ServletModule/loginsetvlet ");
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( " </from> ");
out.println( " </body> ");
out.println( " </html> ");
}
//处理Http Post请求
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
//清理资源
public void destroy() {
}
}
[解决办法]
没有form 表单
因为你的
out.println( " <fron method=post action=/ServletModule/loginsetvlet ");
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( " </from> ");
写错了
不是from 是form