servlet无法加载,求高手解决
doGet中的所有System.out输出都可以正常加载,但是无法转发forward到指定页面,也没有任何报错
另外,这个servlet是用ajax加载的
package com.px2010.servlet;
import com.px2010.visual.*;
import java.io.IOException;
import java.io.PrintWriter;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.px2010.businesslayer.SortManager;
import java.util.ArrayList;
public class TakebillServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public TakebillServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
System.out.println("jhghghghghghghgghghg");
Cookie cookie = this.getCookie("aishubacart", request);
String value = cookie.getValue();
cookie.setMaxAge(0);
response.addCookie(cookie);
String items[] = value.split(" ");
for(int i = 0;i<items.length;i++)
{
System.out.println(items[i]);
}
System.out.println(items.length);
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
SortManager sortmanager =(SortManager)ctx.getBean("sortManager");
ArrayList<Itembill> result =new ArrayList<Itembill>();
for(int i = 0;i<items.length;i++)
{
String info = items[i];
String strSortId = (info.split(":"))[0];
String strItemnumber = (info.split(":"))[1];
Integer sortId = Integer.valueOf(strSortId);
Integer number = Integer.valueOf(strItemnumber);
System.out.println("id:"+strSortId+" "+"number:"+strItemnumber);
sortmanager.setSortId(sortId);
boolean re=sortmanager.FullfillSortInfo();
System.out.println(re);
String sortname = sortmanager.getName();
String company = sortmanager.getCompany();
Double price = sortmanager.getPrice();
Itembill bill = new Itembill();
bill.setSortId(sortId);
bill.setNumber(number.intValue());
bill.setSortName(sortname);
bill.setCompany(company);
bill.setPrice(price*(number.intValue()));
result.add(bill);
}
request.setCharacterEncoding("UTF-8");
request.setAttribute("billlist", result);
Itembill h = result.get(0);
request.getRequestDispatcher("submitOrder.jsp").forward(request, response);
System.out.print(h.getSortName());
}
private Cookie getCookie(String name,HttpServletRequest request)
{
Cookie[] cookies = request.getCookies();
for(int i = 0;i<cookies.length;i++)
{
if(cookies[i].getName().equals(name))
{
return cookies[i];
}
}
return null;
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}