📄 requestservlet.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
* Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
* created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.wstore;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import org.apache.ecs.*;
import org.apache.ecs.xhtml.*;
import org.apache.log4j.Logger;
import org.compiere.util.*;
import org.compiere.www.*;
/**
* Web Request.
*
* @author Jorg Janke
* @version $Id: RequestServlet.java,v 1.3 2003/05/04 06:47:28 jjanke Exp $
*/
public class RequestServlet extends HttpServlet
{
/** Logging */
private Logger log = Logger.getLogger(getClass());
/** Name */
static public final String NAME = "requestServlet";
/**
* Initialize global variables
*
* @param config Configuration
* @throws ServletException
*/
public void init(ServletConfig config)
throws ServletException
{
super.init(config);
if (!WEnv.initWeb(config))
throw new ServletException("RequestServlet.init");
} // init
/**
* Get Servlet information
* @return Info
*/
public String getServletInfo()
{
return "Compiere Web Request Servlet";
} // getServletInfo
/**
* Clean up resources
*/
public void destroy()
{
log.debug("destroy");
} // destroy
/*************************************************************************/
public static final String P_FORWARDTO = "ForwardTo";
public static final String P_SOURCE = "Source";
public static final String P_INFO = "Info";
public static final String P_REQUESTTYPE = "RequestType";
public static final String P_NAME = "Name";
public static final String P_COMPANY = "Company";
public static final String P_ADDRESS = "Address";
public static final String P_CITY = "City";
public static final String P_POSTAL = "Postal";
public static final String P_REGION = "Region";
public static final String P_COUNTRY = "Country";
public static final String P_EMAIL = "EMail";
public static final String P_PHONE = "Phone";
public static final String P_QUESTION = "Question";
/**
* Process the HTTP Get request
* Sends Web Request Page
*
* @param request request
* @param response response
* @throws ServletException
* @throws IOException
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.sendRedirect("request.jsp");
} // doGet
/*************************************************************************/
/**
* Process the HTTP Post request
*
* @param request request
* @param response response
* @throws ServletException
* @throws IOException
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
log.info("doPost from " + request.getRemoteHost() + " - " + request.getRemoteAddr());
// Get Session attributes
HttpSession session = request.getSession(true);
//
Properties ctx = JSPEnv.getCtx(request);
WebUser wu = (WebUser)session.getAttribute(WebUser.NAME);
StringBuffer sql = new StringBuffer ("INSERT INTO W_Request "
+ "(W_Request_ID,AD_Client_ID,AD_Org_ID, "
+ "IsActive,Created,CreatedBy,Updated,UpdatedBy, "
+ "R_RequestType_ID,Question, "
+ "Name,Company, "
+ "Address,City,Postal,Region,Country, "
+ "EMail,Phone, "
+ "PageURL,Referrer, "
+ "AcceptLanguage, "
+ "Remote_Addr,UserAgent, "
+ "C_BPartner_ID,C_BPartner_Contact_ID, "
+ "FindBPartner,Processing,Processed) VALUES (");
//
// W_Request_ID,AD_Client_ID,AD_Org_ID,
int AD_Client_ID = Env.getContextAsInt(ctx, "AD_Client_ID");
int W_Request_ID = DB.getKeyNextNo(AD_Client_ID, "N", "W_Request");
sql.append(W_Request_ID).append(",").append(AD_Client_ID).append(",0, ");
// IsActive,Created,CreatedBy,Updated,UpdatedBy,
sql.append("'Y',SysDate,0,SysDate,0, ");
// RequestType,Question,
String RequestType = request.getParameter(P_REQUESTTYPE);
if (RequestType == null)
RequestType = "null";
String Question = request.getParameter(P_QUESTION);
sql.append(RequestType).append(",")
.append(DB.TO_STRING(Question, 2000)).append(", ");
// Name,Company,
sql.append(DB.TO_STRING(request.getParameter(P_NAME), 60)).append(",")
.append(DB.TO_STRING(request.getParameter(P_COMPANY), 60)).append(", ");
// Address,City,Postal,Region,Country,
sql.append(DB.TO_STRING(request.getParameter(P_ADDRESS), 60)).append(",")
.append(DB.TO_STRING(request.getParameter(P_CITY), 60)).append(",")
.append(DB.TO_STRING(request.getParameter(P_POSTAL), 20)).append(",")
.append(DB.TO_STRING(request.getParameter(P_REGION), 20)).append(",")
.append(DB.TO_STRING(request.getParameter(P_COUNTRY), 20)).append(", ");
// EMail,Phone,
String EMail = request.getParameter(P_EMAIL);
sql.append(DB.TO_STRING(EMail, 60)).append(",")
.append(DB.TO_STRING(request.getParameter(P_PHONE), 20)).append(", ");
// PageURL,Referrer,
String requestURL = request.getRequestURL().toString();
String requestRef = request.getHeader("referer");
String source = request.getParameter(P_SOURCE);
String info = request.getParameter(P_INFO);
if (requestURL == null)
requestURL = "";
if (requestURL.equals(requestRef)) // if URL and Referrer are the same, get source
{
requestRef = source;
source = null;
}
sql.append(DB.TO_STRING(requestURL, 255)).append(",")
.append(DB.TO_STRING(requestRef, 255)).append(", ");
// AcceptLanguage,
sql.append(DB.TO_STRING(request.getHeader("accept-language"), 60)).append(", ");
// Remote_Addr,UserAgent,
sql.append(DB.TO_STRING(request.getRemoteAddr(), 60)).append(",")
.append(DB.TO_STRING(request.getHeader("user-agent"), 60)).append(", ");
// C_BPartner_ID,C_BPartner_Contact_ID
if (wu != null && wu.getC_BPartner_ID() != 0)
sql.append(wu.getC_BPartner_ID()).append(",");
else
sql.append("NULL,");
if (wu != null && wu.getC_BPartner_Contact_ID() != 0)
sql.append(wu.getC_BPartner_Contact_ID()).append(", ");
else
sql.append("NULL, ");
// FindBPartner,Processing,Processed)
sql.append("'N','N','N')");
int no = DB.executeUpdate(sql.toString());
if (no != 1)
{
log.error("post - Request NOT saved - #=" + no);
WUtil.createErrorPage(request, response, this, Env.getCtx(), "Request Process Error");
return;
}
// Send EMail
String subject = "Compiere Web Request";
String message = "Thank you for your request on http://"
+ request.getServerName()
+ request.getContextPath() + "/"
+ "\n\n" + Question;
String SMTPHost = ctx.getProperty("SMTPHost", "localhost");
String RequestEMail = ctx.getProperty("RequestEMail");
String RequestUser = ctx.getProperty("RequestUser");
String RequestUserPw = ctx.getProperty("RequestUserPw");
//
EMail em = new EMail(SMTPHost, RequestEMail, EMail, subject, message);
em.setEMailUser(RequestUser, RequestUserPw);
//
String webOrderEMail = ctx.getProperty("webOrderEMail");
em.addBcc(webOrderEMail);
em.send();
// -- Fini
String ForwardTo = request.getParameter(P_FORWARDTO);
if (ForwardTo == null || ForwardTo.length() == 0)
ForwardTo = "http://www.compiere.org";
WUtil.createForwardPage(response, "Web Request Received - Thanks", ForwardTo);
} // doPost
} // RequestServlet
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -