问题来自这里:
http://bbs.csdn.net/topics/390700523?page=1#post-396671837
他那里的代码servlet的运行目测是通过onload的location指定的
servlet代码:
package user.yourservlet;
import user.yourbean.Lefttopbean;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Lefttop extends HttpServlet{
public void init(ServletConfig config) throws ServletException{
super.init(config);
}
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
Lefttopbean lt=new Lefttopbean();
String information="测试";
lt.setInformation(information);
System.out.println(lt.getInformation());
request.getSession().setAttribute("lefttopbean",lt);
response.sendRedirect("lefttop.jsp");
}
public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
System.out.println("here");
doPost(request, response);
}
}
javabean对应的java类
package user.yourbean;
public class Lefttopbean {
String information=null;
public String getInformation(){
return information;
}
public void setInformation(String w){
information=w;
}
}
web.xml
<servlet>
<servlet-name>lefttop</servlet-name>
<servlet-class>user.yourservlet.Lefttop</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>lefttop</servlet-name>
<url-pattern>/lefttop</url-pattern>
</servlet-mapping>
lefttop.jsp文件
<%@ page contentType="text/html; charset=utf-8" %>
<jsp:useBean id="lefttopbean" scope="session" class="user.yourbean.Lefttopbean"/>
<html>
<body>
<h3><jsp:getProperty name="lefttopbean" property="information" /></h3>
</body>
</html>
运行的时候直接通过访问servlet的url-pattern,在通过servlet内部跳转到jsp文件就可以准确显示了。