Package demo.servlet

Source Code of demo.servlet.UploadPhotoServlet

package demo.servlet;

import java.io.IOException;
import java.util.Date;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.renren.api.client.RenrenApiClient;
import com.renren.api.client.param.impl.SessionKey;
import com.renren.api.client.services.RenrenApiException;

/**
* Servlet implementation class UploadPhotoServlet
*/
public class UploadPhotoServlet extends HttpServlet {
  private static final long serialVersionUID = 1L;
      
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UploadPhotoServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

  /**
   * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
      //判断是否授权过
        String isAuth=(String)request.getParameter("xn_sig_added");
        if(isAuth.equals("0")){
            response.sendRedirect("auth");
            return;
        }
      RequestDispatcher welcomeDispatcher = request.getRequestDispatcher("/views/uploadphoto.jsp");
        welcomeDispatcher.forward(request, response);
  }

  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
      String flag=(String)request.getParameter("flag");
      String sessionKey=(String)request.getSession().getAttribute("session_key");
      if(flag!=null&&sessionKey!=null){
          RenrenApiClient client=RenrenApiClient.getInstance();
          if(flag.equals("local")){
              //上传本地图片
              String filename=(String)request.getParameter("filename");
              filename=new String(filename.getBytes("ISO8859-1"),"UTF-8");
              try{
                  client.getPhotoService().uploadLocalImg(0, filename, "测试上传本地图片"+new Date(),new SessionKey(sessionKey));
              }catch(RenrenApiException e){
                  e.printStackTrace();
              }
             
          }else if(flag.equals("url")){
              //上传网络图片
              String fileurl=(String)request.getParameter("fileurl");
              try{
                  client.getPhotoService().uploadURLImg(0, fileurl, "测试上传网络图片"+new Date(),new SessionKey(sessionKey));
              }catch(RenrenApiException e){
                  e.printStackTrace();
              }
          }
      }
  }

}
TOP

Related Classes of demo.servlet.UploadPhotoServlet

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.