Java项目在浏览器直接访问servlet访问不到怎么回事
代码如下
```
package com.nineplus.cyanbird.servlet;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.alipay.api.AlipayApiException;
import com.alipay.api.internal.util.AlipaySignature;
import com.nineplus.cyanbird.base.constants.AlipayContants;
import com.nineplus.cyanbird.base.constants.OrderStatusConstants;
import com.nineplus.cyanbird.base.dao.FunOrderDao;
import com.nineplus.cyanbird.base.domain.view.FunOrder;
import com.nineplus.cyanbird.base.service.FunOrderService;
import com.nineplus.model.InvokeResult;
public class AlipayServlet extends HttpServlet{
/**
*
*/
private static final long serialVersionUID = 1L;
private FunOrderDao funOrderDao;
private FunOrderService funOrderService;
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
alipayNortify(request,response);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
this.doGet(req, resp);
}
public void alipayNortify(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Map<String,String> params = new HashMap<String,String>();
Map<String,String[]> requestParams = request.getParameterMap();
for (Iterator<String> iter = requestParams.keySet().iterator(); iter.hasNext();) {
String name = (String) iter.next();
String[] values = (String[]) requestParams.get(name);
String valueStr = "";
for (int i = 0; i < values.length; i++) {
valueStr = (i == values.length - 1) ? valueStr + values[i]
: valueStr + values[i] + ",";
}
valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8");
params.put(name, valueStr);
}
boolean signVerified = false;
try {
signVerified = AlipaySignature.rsaCheckV1(params, AlipayContants.alipay_public_key, AlipayContants.charset, AlipayContants.sign_type);
} catch (AlipayApiException e) {
e.printStackTrace();
}
if(signVerified) {
String seller_id = new String(request.getParameter("app_id").getBytes("ISO-8859-1"),"UTF-8");
if(!seller_id.equals(AlipayContants.app_id)){
System.out.println("fail");
}
String out_trade_no = new String(request.getParameter("out_trade_no").getBytes("ISO-8859-1"),"UTF-8");
String total_amount = new String(request.getParameter("total_amount").getBytes("ISO-8859-1"),"UTF-8");
String trade_status = new String(request.getParameter("trade_status").getBytes("ISO-8859-1"),"UTF-8");
Float totalCost = new Float(total_amount);
FunOrder f = new FunOrder();
f.setId(out_trade_no);
f.setTotalCost(totalCost);
FunOrder exitF = funOrderDao.get(f);
if(exitF==null){
System.out.println("fail");
}
if(trade_status.equals("TRADE_FINISHED")){
if(!exitF.getStatus().equals(OrderStatusConstants.FINISH)){
exitF.setStatus(OrderStatusConstants.FINISH);
funOrderDao.update(exitF);
InvokeResult r = funOrderService.commitFunOrderSuccess(exitF);
if(r.getStatus()!=1){
System.out.println("fail");
}
}
}else if (trade_status.equals("TRADE_SUCCESS")){
if(!exitF.getStatus().equals(OrderStatusConstants.FINISH)){
exitF.setStatus(OrderStatusConstants.FINISH);
funOrderDao.update(exitF);
InvokeResult r = funOrderService.commitFunOrderSuccess(exitF);
if(r.getStatus()!=1){
System.out.println("fail");
}
}
}
System.out.println("success");
}else {//验证失败
System.out.println("fail");
}
}
}
web中配置
<servlet>
<servlet-name>AlipayServlet</servlet-name>
<servlet-class>com.nineplus.cyanbird.servlet.AlipayServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AlipayServlet</servlet-name>
<url-pattern>/alipayServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>WeChatServlet</servlet-name>
<servlet-class>com.nineplus.cyanbird.servlet.WeChatServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>WeChatServlet</servlet-name>
<url-pattern>/weChatServlet</url-pattern>
</servlet-mapping>
```
浏览器输入:http://localhost:8080/aaa(项目名)/AlipayServlet/alipayServlet
显示如下
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论