日期:2014-05-18  浏览次数:20798 次

一个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可以去掉了
------解决方案--------------------
探讨
引用:
这个页面转起来好简单的吧,写个action继承ActionSupport的类,再弄个数据库连接类被前面aciton调用,再写个user的model,整整页面就搞定了

大哥,我只想简单的改改先,毕竟也是刚学,太深的我也不会,只是想知道在servlet里的HttpServletRequest,HttpServletResponse,还有HttpSession在struts2可不可以只是改一下类名就实现的,貌似前两个
HttpServletRequest request = ServletActionContex…