📄 weatherreturn.java
字号:
/*
*
*/
import java.io.*;
import java.text.*;
import java.sql.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
*
*
* @author Chen Xin Wu
*/
public class WeatherReturn extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
HtmlOut htmlOut = new HtmlOut (response);
// 得到名字和口令
String name,pass;
Person person = new Person();
person.setName (CommonMethods.GetUserName(request));
pass = CommonMethods.GetUserPass (request);
if (pass ==null)
pass="";
else
pass=pass.trim();
if( person.getName ()==null || (!person.checkPassword(pass)) )
{
htmlOut.setErrorID (htmlOut.USER_NEED_LOGIN,
"","用户不存在或用户密码错误","Login?action=reLog");
htmlOut.outHtml ();
return;
}
name= person.getName ().trim();
int i=0 ,length=0;
String[] result =request.getParameterValues ("col");
if ((result == null)||(result.length ==0))
{
htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE ,
"","请选择要显示天气预报的城市","EditChannel?channel=weather");
htmlOut.outHtml ();
return;
}
length = result.length ;
for (i=0;i < length;i++)
{
result[i]= CommonMethods.DealWithGBCodeOfRequest (result[i]);
}
//将用户定制的城市信息插入ps_weather表中
DBOperater DB = new DBOperater ("ps_weather");
DB.executeUpdate ( "delete from ps_weather where user_name='"+ name +"'" );
for (i=0;i<length;i++)
{
DB.executeUpdate ( "INSERT INTO ps_weather(User_name, QX_dz) VALUES('"+name+"'"+","+"'"+result[i]+"'"+")");
}
String sHours=new String ();
sHours = request.getParameter ("hour");
System.out.println ("hours:"+sHours);
if ((sHours==null)||(sHours.trim ().length ()==0))
{
sHours="0";
System.out.println ("hours:"+sHours);
}
/***********************************/
//get all citys info now;
String sPhone=null;
ResultSet rs11=DB.executeQuery("select mobile from person where username='"+ name +"'");
try{
if( rs11!=null && rs11.next () ){
sPhone = CommonMethods.getFieldValue(rs11,"mobile");
}
}catch(Exception e){
}
String sMsg="您定制了:";
for (i=0;i<length;i++)
{
sMsg+=result[i];
if( i!=length-1)
sMsg+=",";
}
sMsg+="的天气预报,您将在每天";
sMsg+=sHours;
sMsg+="时收到讯息---声讯通公司";
System.out.println (sMsg);
if( sPhone!=null )
CommonMethods.sendSMS(sPhone,sMsg);
/***********************************/
DB.close ();
//将用户定制的提醒信息插入person表中
int nHours=0;
try{
nHours=Integer.valueOf (sHours).intValue ();
}catch(Exception e){
nHours=0;
}
System.out.println ("nHours"+nHours);
int nAwoke=0;
String [] sAwoke = request.getParameterValues ("awoke");
if ((sAwoke==null)||(sAwoke.length ==0))
{
nAwoke = 0;
nHours = 0;
}
else
{
length =sAwoke.length ;
for (i=0;i<length;i++)
{
sAwoke[i]=CommonMethods.DealWithGBCodeOfRequest (sAwoke[i]);
if ((sAwoke[i]==null)||(sAwoke[i].trim ().length ()==0))
continue;
if (sAwoke[i].trim ().compareTo ("SMS")==0)
nAwoke +=1;
if (sAwoke[i].trim ().compareTo ("寻呼")==0)
nAwoke +=2;
}
}
DBOperater DB1=new DBOperater ("person");
DB1.executeUpdate ("update person set weatherawoke='"+nAwoke+"',weatherawokehour='"+nHours+"' where username='"+name+"'");
DB1.close ();
response.sendRedirect ("Login?channel=weather");
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
doGet(request,response);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -