严重: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 16 in the jsp file: /register.jsp
User cannot be resolved to a type
13:  String phone = request.getParameter("phone");
14:  String addr = request.getParameter("addr");
15: 
16:  User u = new User();
17:  u.setUsername(username);
18:  u.setPassword(password);
19:  u.setPhone(phone);
An error occurred at line: 16 in the jsp file: /register.jsp
User cannot be resolved to a type
13:  String phone = request.getParameter("phone");
14:  String addr = request.getParameter("addr");
15: 
16:  User u = new User();
17:  u.setUsername(username);
18:  u.setPassword(password);
19:  u.setPhone(phone);
Stacktrace:
at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:317)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)上面是eclipse报的错误,下面是我的代码:
<%@ page language="java" import="com.bjsxt.shopping.*"  pageEncoding="GBK"%><%request.setCharacterEncoding("GBK");
String action = request.getParameter("action");if(action != null && action.equals("register")) {
String username = request.getParameter("username");
String password = request.getParameter("password");
//String password2 = request.getParameter("password2");
String phone = request.getParameter("phone");
String addr = request.getParameter("addr");

User u = new User();
u.setUsername(username);
u.setPassword(password);
u.setPhone(phone);
u.setAddr(addr);
u.setRdate(new java.util.Date(System.currentTimeMillis())); u.save();
out.println("注册成功!恭喜!");
return;
}
 %>

解决方案 »

  1.   

    An error occurred at line: 16 in the jsp file: /register.jsp
    User cannot be resolved to a type
    16: User u = new User();有import User这个类么?
    <%@ page import="xxoo.xxoo.User" %>该类有正确跟应用一起部署么?比如:WEB-INF\classes\ 是否有这个类?
      

  2.   

    jsp编译错误,检查一下com.bjsxt.shopping.*这个包下有没有User这个类
      

  3.   

    com.bjsxt.shopping.*有User这个类,给你们看看我的代码:package com.bjsxt.shopping;import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.SQLException;
    import java.sql.Timestamp;
    import java.util.Date;import com.bjsxt.shopping.util.DB;public class User {
    private int id ;
    private String username ;
    private String password ;
    private String phone ;
    private String addr ;
    private Date rdate ;

    public int getId() {
    return id;
    }
    public void setId(int id) {
    this.id = id;
    }
    public String getUsername() {
    return username;
    }
    public void setUsername(String username) {
    this.username = username;
    }
    public String getPassword() {
    return password;
    }
    public void setPassword(String password) {
    this.password = password;
    }
    public String getPhone() {
    return phone;
    }
    public void setPhone(String phone) {
    this.phone = phone;
    }
    public String getAddr() {
    return addr;
    }
    public void setAddr(String addr) {
    this.addr = addr;
    }
    public Date getRdate() {
    return rdate;
    }
    public void setRdate(Date rdate) {
    this.rdate = rdate;
    }
    public void save(){
    Connection conn = null;
    PreparedStatement pstmt = null;
    try {
    conn = DB.getConn();
        String sql = "insert into user values (null,?,?,?,?,?)";
        pstmt = DB.getPStmt(conn, sql);

    pstmt.setString(1, username);
    pstmt.setString(2, password);
    pstmt.setString(3,phone);
    pstmt.setString(4,addr);
    pstmt.setTimestamp(5,new Timestamp(rdate.getTime()));

    pstmt.executeUpdate();
    } catch (SQLException e) {
    e.printStackTrace();
    }finally{
    DB.closeStmt(pstmt);
    DB.closeConn(conn);
    }
    }

    }我的build/classes/com/bjsxt/shopping/User.class  这个底下有User类,WEB-INF\classes\ 没有这个类我调试了一个下午都没有成功,急啊,本来今天休息,可还是轻松不了,所以又来调试了,求大师帮忙啊?
      

  4.   

    User cannot be resolved to a type
    直接 import="xxx.xxx.User" 不要 xxx.xxx.* 
      

  5.   

    MyEclipse6.0编译后的类无法自动发到WebRoot/WEB-INF/classes文件夹下
    看看这个吧