📄 useraction.java
字号:
package action;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ResourceBundle;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import dao.userDao;
import Beans.userDto;
public class userAction extends HttpServlet {
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String action=request.getParameter("action");
userDto dto=new userDto();
userDao dao=new userDao();
RequestDispatcher dispatcher=null;
if(action!=null&&action.equals("login"))
{
dto.setName(request.getParameter("name")) ;
dto.setPass(request.getParameter("pass"));
boolean f=false;
f=dao.login(dto);
ResourceBundle res=ResourceBundle.getBundle("msg");
if(f==true)
{
request.setAttribute("login",res.getString("login.ok"));
}
else
{
request.setAttribute("error",res.getString("login.error"));
}
}
if(action!=null&&action.equals("del"))
{
int i=0;
String id=request.getParameter("id");
i=dao.delbook(id);
ResourceBundle res=ResourceBundle.getBundle("msg");
if(i!=0)
{
request.setAttribute("del",res.getString("del.ok"));
}
else
{
request.setAttribute("del",res.getString("del.error"));
}
}
if(action!=null&&action.equals("update"))
{
int i=0;
dto.setId(request.getParameter("id"));
dto.setName(request.getParameter("name"));
dto.setPass(request.getParameter("pass"));
i=dao.upbook(dto);
ResourceBundle res=ResourceBundle.getBundle("msg");
if(i!=0)
{
request.setAttribute("update",res.getString("update.ok"));
}
else
{
request.setAttribute("update",res.getString("update.error"));
}
}
dispatcher =request.getRequestDispatcher("/msg.jsp") ;
dispatcher.forward(request,response);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -