servlet 中创建bean出错 20
一个简单的MVC结构,目录结构WEB-INF/classes/myservlet中放servlet,EB-INF/classes/myservlet/mybean中放be...
一个简单的MVC结构,目录结构WEB-INF/classes/myservlet中放servlet,EB-INF/classes/myservlet/mybean中放bean,servlet打进myservlet包,bean打进mybean包,在servlet中引入mybean包,new了bean对象,放进request,编译都没错。但是当在浏览器中访问servlet时,总是报java.lang.NoClassDefFoundError: mybean/MyNumber错,找不到mybean下的MyNumber,不知为何,请知道的网友说说,谢谢!下面附上servlet的代码:
package myservlet;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import mybean.*;
public class HandleJS extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
int a1 = Integer.parseInt( request.getParameter("a1") );//接受表单的数据
int d = Integer.parseInt( request.getParameter("d") );
int n = Integer.parseInt( request.getParameter("n") );
int su = a1*n + ( n*(n-1)*d )/2;
MySum mySum = new MySum();//这儿在浏览器中时总报错,但是编译啥的都没错,也能找到MySum
mySum.setA1(a1);
mySum.setD(d);
mySum.setN(n);
mySum.setSum(su);
request.setAttribute("mySum", mySum);
request.getRequestDispatcher("showSum.jsp").forward(request, response);
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
} 展开
package myservlet;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import mybean.*;
public class HandleJS extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
int a1 = Integer.parseInt( request.getParameter("a1") );//接受表单的数据
int d = Integer.parseInt( request.getParameter("d") );
int n = Integer.parseInt( request.getParameter("n") );
int su = a1*n + ( n*(n-1)*d )/2;
MySum mySum = new MySum();//这儿在浏览器中时总报错,但是编译啥的都没错,也能找到MySum
mySum.setA1(a1);
mySum.setD(d);
mySum.setN(n);
mySum.setSum(su);
request.setAttribute("mySum", mySum);
request.getRequestDispatcher("showSum.jsp").forward(request, response);
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询