一个servlet里如何转为struts2,主要是servlet的内置对象不知道怎么转?
package cn.kun.admin;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import cn.kun.db.DbConnectionManager;
public class adminLogin extends HttpServlet{
protected void doPost(HttpServletRequest req, HttpServletResponse res)throws
IOException,
ServletException{
doGet(req,res);
}
protected void doGet(HttpServletRequest req, HttpServletResponse res)throws IOException,ServletException{
res.setContentType("text/html;charset=gb2312");//包含响应中文情况
PrintWriter out = res.getWriter();//获得一个流
String admin = new String(req.getParameter("admin").getBytes("ISO-8859-1"));
String passwd = req.getParameter("passwd");
String checkCode = req.getParameter("checkCode");
String sqlStr;
ResultSet rs,rsS;
HttpSession session = req.getSession();
sqlStr = "select * from my_admin where uid='"+admin+"'and passwd='"+passwd+"'";
if(checkCode.equals(session.getAttribute("rand"))){
DbConnectionManager dbm = new DbConnectionManager();
try{
rs=dbm.executeQuery(sqlStr);
if( rs.next()){
session.setAttribute("admin",admin);
res.sendRedirect("updatePage.jsp");
}
else{
session.setAttribute("errMsg","对不起,你的用户名或者密码有错,请查证再登录");
res.sendRedirect("error.jsp");
}
}
catch(Exception e){
e.printStackTrace();
}
}
else{
session.setAttribute("errMsg","对不起,你的验证码有错,请查证再登录");
res.sendRedirect("error.jsp");
}
}
}
------解决方案--------------------那你把extends HttpServlet改成extends ActionSupport,下面再用map就不该有问题, 什么HttpServletRequest,HttpServletResponse可以去掉了
------解决方案--------------------