servlet无法加载,求高手解决

dachuandavid 2010-12-18 07:57:52
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
}

}
...全文
182 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yaoweijq 2010-12-20
  • 打赏
  • 举报
回复
...
jquery还有这作用。。。
[Quote=引用 2 楼 dachuandavid 的回复:]
已经解决了,是jQuery的问题,把所有跳转和url给屏蔽了
[/Quote]
dreaming_java 2010-12-20
  • 打赏
  • 举报
回复
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");

这里错了 spring context 一个应用初始化一次。
Hugo_Ken 2010-12-20
  • 打赏
  • 举报
回复
JQuery是异步的,无需跳转!
昵称很不好取 2010-12-19
  • 打赏
  • 举报
回复
接分~~
Jlins 2010-12-19
  • 打赏
  • 举报
回复
恭喜 恭喜 自己动手 丰衣足食[Quote=引用 2 楼 dachuandavid 的回复:]

已经解决了,是jQuery的问题,把所有跳转和url给屏蔽了
[/Quote]
dachuandavid 2010-12-18
  • 打赏
  • 举报
回复
已经解决了,是jQuery的问题,把所有跳转和url给屏蔽了
UPC_思念 2010-12-18
  • 打赏
  • 举报
回复
debug会吗?看看程序咋运行的

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧