📄 userpkaction.java
字号:
package com.yourcompany.struts.action;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.yourcompany.struts.BizException;
import com.yourcompany.struts.JDBCTraining;
import com.yourcompany.struts.form.UserPkForm;
@SuppressWarnings("serial")
public class UserPkAction extends Action {
@SuppressWarnings("unchecked")
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
UserPkForm userPkForm = (UserPkForm) form;
String[] Pk=userPkForm.getUsid();
if ("edit".equalsIgnoreCase(mapping.getParameter())){
String sql="select * from user_info where userid=?";
ArrayList<?> list = JDBCTraining.query(sql, Pk);
request.getSession().setAttribute("userInfo", list.get(0));
return mapping.findForward("it");
}
if ("pic".equalsIgnoreCase(mapping.getParameter())){
String sql="select * from user_info where userid=?";
ArrayList<?> list = JDBCTraining.query(sql, Pk);
Map row = (Map)list.get(0);
byte[] pic = (byte[])row.get("picture");
if (pic!=null){
try {
response.getOutputStream().write(pic);
} catch (IOException e) {
throw new BizException("显示图片出错",e);
}
}
return null;
}
if ("pic".equalsIgnoreCase(mapping.getParameter())){
String sql="select * from user_info where userid=?";
ArrayList<?> list = JDBCTraining.query(sql, Pk);
HashMap row = (HashMap)list.get(0);
byte[] bs = (byte[])row.get("picture");
if (bs!=null){
try {
response.getOutputStream().write(bs);
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
if ("down".equalsIgnoreCase(mapping.getParameter())){
String sql="select * from user_info where userid=?";
ArrayList<?> list = JDBCTraining.query(sql, Pk);
HashMap row = (HashMap)list.get(0);
byte[] bs = (byte[])row.get("picture");
if (bs!=null){
//response.setContentType("application/octet-stream");
response.setContentLength(bs.length);
response.setHeader("Content-Disposition", "attachment:fileName=test.jpg");
try {
response.getOutputStream().write(bs);
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
String sql="delete from user_info where userid=?";
for(String Pks:Pk){
JDBCTraining.update(sql, Pks);
}
return mapping.findForward("it");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -