📄 myszsave.java
字号:
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
/**
*
*
* @author Zhu Ke Jun
*/
public class MyszSave extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
HtmlOut htmlOut = new HtmlOut (response);
String queryString,selectchannel[],selectedchannel[],type="";
int start=0,i=0,posi,selectcount,selectedcount,j,orderid,p;
//exist 用来控制对数据库纪录的操作
boolean exist;
exist=false;
ResultSet rs;
String selectvalue,username;
Person person = new Person();
selectchannel=new String[100];
selectedchannel=new String [100];
person.setName (CommonMethods.GetUserName(request));
username=person.username;
Enumeration e;
e = request.getParameterNames();
selectvalue=request.getParameter("selectValue");
p=Integer.valueOf(request.getParameter ("p")).intValue ();
//获取用户选择的信息
while(true)
{
posi = selectvalue.indexOf(",",start);
if(posi==-1)
break;
selectchannel[i]=selectvalue.substring (start,posi);
start=start+selectchannel[i].length()+1 ;
i=i+1;
}
selectcount=i;
DBOperater DB = new DBOperater ("userchannel");
queryString ="select channelid from userchannel where username='"+CommonMethods.DealWithSQLParameter(username)+"'";
rs = DB.executeQuery(queryString);
//已选的存入数组selectedchannel[]
i=0;
if(rs!=null){
try{
while(rs.next())
{
String sChannel = rs.getString(1);
selectedchannel[i]=sChannel.trim();
i=i+1;
}
}catch(Exception er){
}
}
selectedcount=i;
//添加
for(i=0;i<selectcount;i++)
{
for(j=0;j<selectedcount;j++)
{
if(selectchannel[i].compareTo(selectedchannel[j])==0)
{
exist=true;
}
}
if(exist==false)
{
queryString="select type from channel where channelid='"+CommonMethods.DealWithSQLParameter(selectchannel[i])+"'";
rs=DB.executeQuery(queryString);
if(rs!=null){
try{
rs.next();
type=rs.getString (1).trim();
queryString="select max(orderid) from userchannel where pagenumber="+p+" and username='"+CommonMethods.DealWithSQLParameter(username)+"' and type='"+CommonMethods.DealWithSQLParameter(type)+"'";
}catch(Exception er){
}
}
rs=DB.executeQuery (queryString);
if(rs!=null){
try{
if(rs.next ())
{
orderid=rs.getInt(1)+1;
}
else
orderid=1;
queryString ="insert into userchannel(username,channelid,pagenumber,orderid,type) values('"+CommonMethods.DealWithSQLParameter(username)+"','"+CommonMethods.DealWithSQLParameter(selectchannel[i])+"',"+p+","+orderid+",'"+CommonMethods.DealWithSQLParameter(type)+"')";
}catch(Exception er){
}
}
DB.executeUpdate (queryString);
}
exist=false;
}
//删除
exist=true;
for(i=0;i<selectedcount;i++)
{
for(j=0;j<selectcount;j++)
{
if(selectedchannel[i].compareTo(selectchannel[j])==0)
{
exist=false;
}
}
if(exist==true)
{
queryString ="delete from userchannel where username='"+CommonMethods.DealWithSQLParameter(username)+"' and channelid='"+CommonMethods.DealWithSQLParameter(selectedchannel[i])+"' and pagenumber="+p;
DB.executeUpdate (queryString);
}
exist=true;
}
DB.close ();
htmlOut.setRedirect("Login?p="+p);
htmlOut.outHtml ();
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
doGet(request,response);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -