servlet中getParameter方法获取的值为null
packageeg.load;importjavax.servlet.http.*;importjava.io.*;importjavax.servlet.*;publi...
package eg.load;
import javax.servlet.http.*;
import java.io.*;
import javax.servlet.*;
public class Login extends HttpServlet{
public void destroy(){
super.destroy();//just puts "destroy" string in log
}
//处理get请求
public void doGet(HttpServletRequest req,HttpServletResponse res){
//业务逻辑
try{
//解决中文乱码
res.setContentType("text/html;charset=gbk");
PrintWriter pw=res.getWriter();
//登录界面
pw.println("<html>");
pw.println("<body>");
pw.println("<h1>登陆界面</h1>");
pw.println("<form action=logincl method=get>");
pw.println("用户名:");
pw.println("<input type=text name=username/><br/>");
pw.println("密 码:");
pw.println("<input type=password name=password/><br/>");
pw.println("<input type=submit value=确定>");
pw.println("<input type=reset value=取消>");
pw.println("</form>");
pw.println("<body>");
pw.println("<html>");
}
catch(Exception ex){
ex.printStackTrace();
}
}
//处理post请求
public void doPost(HttpServletRequest req,HttpServletResponse res){
this.doGet(req,res);
}
public void init()throws ServletException{
}
} 展开
import javax.servlet.http.*;
import java.io.*;
import javax.servlet.*;
public class Login extends HttpServlet{
public void destroy(){
super.destroy();//just puts "destroy" string in log
}
//处理get请求
public void doGet(HttpServletRequest req,HttpServletResponse res){
//业务逻辑
try{
//解决中文乱码
res.setContentType("text/html;charset=gbk");
PrintWriter pw=res.getWriter();
//登录界面
pw.println("<html>");
pw.println("<body>");
pw.println("<h1>登陆界面</h1>");
pw.println("<form action=logincl method=get>");
pw.println("用户名:");
pw.println("<input type=text name=username/><br/>");
pw.println("密 码:");
pw.println("<input type=password name=password/><br/>");
pw.println("<input type=submit value=确定>");
pw.println("<input type=reset value=取消>");
pw.println("</form>");
pw.println("<body>");
pw.println("<html>");
}
catch(Exception ex){
ex.printStackTrace();
}
}
//处理post请求
public void doPost(HttpServletRequest req,HttpServletResponse res){
this.doGet(req,res);
}
public void init()throws ServletException{
}
} 展开
1个回答
2013-10-30
展开全部
pw.println("<input type=text name=username/><br/>");
这样输出HTML要注意属性值是带引号的,改成
pw.println("<input type='text' name='username'/><br/>");
试一下
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询