如何将多个实体对象的servlet整合进一个主servlet中?
- 内容介绍
- 文章标签
- 相关推荐
本文共计885个文字,预计阅读时间需要4分钟。
所有关于一个实体类的servlet封装在一起,成为主servlet的方法,通过反射调用方法+protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {request.setChar
所有关于一个实体类的servlet封装在一起,成为主servlet的方法,通过反射调用方法protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String type=request.getParameter("type");
sus=new StuUserServlet();
for(Method me:sus.getClass().getDeclaredMethods()){
if(me.getName().equalsIgnoreCase(type)){
try {
System.out.println(me.getName());
me.invoke(this,request,response);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
@SuppressWarnings("all")
private void addStuUser(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
String username=URLDecoder.decode(request.getParameter("username"), "utf-8");
String password=request.getParameter("password");
int sno=Integer.parseInt(request.getParameter("sno"));
String sql="insert into stuuser values(?,?,?)";
ArrayList list=new ArrayList();
list.add(username);
list.add(password);
list.add(sno);
sub.CUDStuUser(sql, list);
sus.pagHref(request, response);
// response.sendRedirect("StuUserServlet?type=pagHref&pageIndex="+request.getParameter("pageIndex")+"&pageSize="+request.getParameter("pageSize")+"&maxIndex="+request.getParameter("maxIndex")+"");
}
@SuppressWarnings("all")
private void alterStuUser(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
String username=URLDecoder.decode(request.getParameter("username"), "utf-8");
String password=request.getParameter("password");
int sno=Integer.parseInt(request.getParameter("sno"));
int id=Integer.parseInt(request.getParameter("id"));
String sql="update stuuser set username=?,password=?,sno=? where sno=? ";
@SuppressWarnings("rawtypes")
ArrayList list=new ArrayList();
list.add(username);
list.add(password);
list.add(sno);
list.add(id);
sub.CUDStuUser(sql, list);
// response.sendRedirect("StuUserServlet?type=pagHref&pageIndex="+request.getParameter("pageIndex")+"&pageSize="+request.getParameter("pageSize")+"&maxIndex="+request.getParameter("maxIndex")+"");
sus.pagHref(request, response);
}
@SuppressWarnings("unused")
private void delStuUser(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
int id=Integer.parseInt(request.getParameter("id"));
String sql="delete from stuuser where sno=?";
sub.delete(sql, id);
System.out.println(request.getParameter("pageIndex"));
// request.getRequestDispatcher("StuUserServlet?type=pagHref&pageIndex="+request.getParameter("pageIndex")+"&pageSize="+request.getParameter("pageSize")+"&maxIndex="+request.getParameter("maxIndex")+"").forward(request, response);;
sus.pagHref(request, response);
}
@SuppressWarnings("all")
private void loginCheck(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{
String name=request.getParameter("userName");
String pwd=request.getParameter("passWord");
if(name!=null&&pwd!=null&&name.length()>=4&&name.length()<=15&&pwd.length()>=3&&pwd.length()<=15){
String sql="select * from stuuser where username=? and password=?";
ArrayList list=new ArrayList();
ArrayList
本文共计885个文字,预计阅读时间需要4分钟。
所有关于一个实体类的servlet封装在一起,成为主servlet的方法,通过反射调用方法+protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {request.setChar
所有关于一个实体类的servlet封装在一起,成为主servlet的方法,通过反射调用方法protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String type=request.getParameter("type");
sus=new StuUserServlet();
for(Method me:sus.getClass().getDeclaredMethods()){
if(me.getName().equalsIgnoreCase(type)){
try {
System.out.println(me.getName());
me.invoke(this,request,response);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
@SuppressWarnings("all")
private void addStuUser(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
String username=URLDecoder.decode(request.getParameter("username"), "utf-8");
String password=request.getParameter("password");
int sno=Integer.parseInt(request.getParameter("sno"));
String sql="insert into stuuser values(?,?,?)";
ArrayList list=new ArrayList();
list.add(username);
list.add(password);
list.add(sno);
sub.CUDStuUser(sql, list);
sus.pagHref(request, response);
// response.sendRedirect("StuUserServlet?type=pagHref&pageIndex="+request.getParameter("pageIndex")+"&pageSize="+request.getParameter("pageSize")+"&maxIndex="+request.getParameter("maxIndex")+"");
}
@SuppressWarnings("all")
private void alterStuUser(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
String username=URLDecoder.decode(request.getParameter("username"), "utf-8");
String password=request.getParameter("password");
int sno=Integer.parseInt(request.getParameter("sno"));
int id=Integer.parseInt(request.getParameter("id"));
String sql="update stuuser set username=?,password=?,sno=? where sno=? ";
@SuppressWarnings("rawtypes")
ArrayList list=new ArrayList();
list.add(username);
list.add(password);
list.add(sno);
list.add(id);
sub.CUDStuUser(sql, list);
// response.sendRedirect("StuUserServlet?type=pagHref&pageIndex="+request.getParameter("pageIndex")+"&pageSize="+request.getParameter("pageSize")+"&maxIndex="+request.getParameter("maxIndex")+"");
sus.pagHref(request, response);
}
@SuppressWarnings("unused")
private void delStuUser(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
int id=Integer.parseInt(request.getParameter("id"));
String sql="delete from stuuser where sno=?";
sub.delete(sql, id);
System.out.println(request.getParameter("pageIndex"));
// request.getRequestDispatcher("StuUserServlet?type=pagHref&pageIndex="+request.getParameter("pageIndex")+"&pageSize="+request.getParameter("pageSize")+"&maxIndex="+request.getParameter("maxIndex")+"").forward(request, response);;
sus.pagHref(request, response);
}
@SuppressWarnings("all")
private void loginCheck(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{
String name=request.getParameter("userName");
String pwd=request.getParameter("passWord");
if(name!=null&&pwd!=null&&name.length()>=4&&name.length()<=15&&pwd.length()>=3&&pwd.length()<=15){
String sql="select * from stuuser where username=? and password=?";
ArrayList list=new ArrayList();
ArrayList

