开发者社区> 问答> 正文

一个关于Javaweb网页跳转的问题

一下是我的代码

Insert.java

 
package com.Servlet;
 
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import com.bean.SqlBean;
import com.bean.JavaBean;
 
public class Insert extends HttpServlet {
 
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
 
    /**
     * The doDelete method of the servlet. <br>
     *
     * This method is called when a HTTP delete request is received.
     * 
     * @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 doDelete(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
 
        // 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");
           doPost(request,response);
         
    }
 
    /**
     * 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 {
 
        response.setContentType("text/html");
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        //获取前台页面数据
        String name =request.getParameter("name");
        String password =request.getParameter("password");
        String sex =request.getParameter("sex");
        String sage = request.getParameter("age");
        int age  =Integer.parseInt(sage);
         
        //封装到JavaBean对象中去
        JavaBean jBean = new JavaBean();
         
        jBean.setName(name);
        jBean.setPassword(password);
        jBean.setSex(sex);
        jBean.setAge(age);
         
        //调用模型层
        String sql = "insert into TestNXSC(Name,Password,Sex,Age) values(?,?,?,?)";
        SqlBean  sBean = new SqlBean();
        int count =sBean.getInsert(sql,jBean);
        String url="";
        if(count>0)
        {
            url="SearchList.jsp";
        }
        else
        {
            url ="error.jsp";
            request.setAttribute("error", "ע��");
        }
        //转发ת
        request.getRequestDispatcher("SearchList.jsp").forward(request, response);
    }
}
 

报错



exception

javax.servlet.ServletException: Error instantiating servlet class com.servlet.Insert
   org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
   org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
   org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
   org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
   org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
   org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
   java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
   org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
   java.lang.Thread.run(Thread.java:745)
root cause

java.lang.ClassNotFoundException: com.servlet.Insert
   org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1308)
   org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1142)
   org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
   org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
   org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
   org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
   org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
   org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
   java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
   org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
   java.lang.Thread.run(Thread.java:745)

展开
收起
爵霸 2016-03-23 15:07:15 4119 0
1 条回答
写回答
取消 提交回答
  • 个人对建模比较关注

    大小写问题:报错显示 com.servlet.Insert 你的代码显示 package com.Servlet;
    如果用windows修改过包名,则svn提交时不会大小写敏感

    2019-07-17 19:11:12
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载