简单的报表项目传值不显示

仿照慕课中的报表项目http://www.imooc.com/learn/375  但是点击生成报表 显示404错误


这是JSP代码

<%@ page language="java" import="java.util.*,beans.*" pageEncoding="utf-8"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>

    <base href="<%=basePath%>">

    

    <title>My JSP 'index.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">    

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">

<!--

<link rel="stylesheet" type="text/css" href="styles.css">

-->

<style type="text/css">

.table-c {border-right: solid black;border-bottom: solid black} 

.table-c td{border-left: solid black;border-top: solid black;padding: 10px 10px}

</style>

  </head>

  

  <body>

    <form action="servlet/MyServlet" method="post">

    <input type="submit" value="生成报表">

    </form>

    

    <table class="table-c">

    <tr class="trcss">

    <td colspan="6" align="center"><strong>亚思晟公司职员信息表</strong></td>

    </tr>

    <tr>

    <td>编号</td>

    <td>用户名</td>

    <td>公司名称</td>

    <td>公司地址</td>

    <td>公司电话</td>

    <td>电子邮件</td>

    </tr>

    

    <%

    List list = null;

    if(session.getAttribute("chart")!=null){

    list = (List)session.getAttribute("chart"); //取到servlet中的list

    if(list.size()>0){

    int temp = 0;

    UserInfo userinfo;

    for(int i=0;i<1;i++){

    userinfo = new UserInfo(); 

    userinfo = (UserInfo)list.get(i);

    %>

<tr>

<td><%=userinfo.getId() %></td>

<td><%=userinfo.getFullname() %></td>

<td><%=userinfo.getCompanyname() %></td>

<td><%=userinfo.getCompanyaddress() %></td>

<td><%=userinfo.getTel()%></td>

<td><%=userinfo.getEmail() %></td>

</tr>

<%

}

    }

    }

     %>

    </table>

  </body>

</html>

这是 servlet代码 

package servlet;


import java.io.IOException;

import java.io.PrintWriter;

import java.util.List;


import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;


import JDBCservice.Service;


public class MyServlet extends HttpServlet {


/**

* Constructor of the object.

*/

public MyServlet() {

super();

}


/**

* Destruction of the servlet. <br>

*/

public void destroy() {

super.destroy(); // Just puts "destroy" string in log

// Put your code here

}


/**

* The doGet method of the servlet. <br>

*

* This method is called when a form has its tag value method equals to get.

* @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 {


response.setContentType("text/html");

PrintWriter out = response.getWriter();

out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");

out.println("<HTML>");

out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");

out.println("  <BODY>");

out.print("    This is ");

out.print(this.getClass());

out.println(", using the GET method");

out.println("  </BODY>");

out.println("</HTML>");

out.flush();

out.close();

}


/**

* 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 doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {


List list;

Service service = new Service();

list = service.getChart();

request.getSession().setAttribute("chart",list);

response.sendRedirect("index.jsp");

}


/**

* Initialization of the servlet. <br>

*

* @throws ServletException if an error occurs

*/

public void init() throws ServletException {

// Put your code here

}


}这是XML中的代码

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">

  <display-name></display-name>

  <servlet>

    <description>This is the description of my J2EE component</description>

    <display-name>This is the display name of my J2EE component</display-name>

    <servlet-name>MyServlet</servlet-name>

    <servlet-class>servlet.MyServlet</servlet-class>

  </servlet>

  <servlet-mapping>

    <servlet-name>MyServlet</servlet-name>

    <url-pattern>/servlet/MyServlet</url-pattern>

  </servlet-mapping>

  <welcome-file-list>

    <welcome-file>index.jsp</welcome-file>

  </welcome-file-list>

</web-app>

请问哪里出错了?????????谢谢!!!!!!

frank_mojito
浏览 996回答 1
1回答

梦影剑魂

肯定是访问路径没写对,找不到指定资源文件。你试下在servlet中dopost()方法的response.sendRedirect("index.jsp");重定向的路径前加个/,看下可以吗
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java