该模块尚未部署,

时间:2016-09-18 09:12:42

标签: java servlets web.xml

请仔细了解这里发生的事情,我有一个部署描述符web.xml,其中url模式映射到servlet,例如这个

  <servlet>
    <servlet-name>ControllerServlet</servlet-name>
    <servlet-class>>controller.ControllerServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>ControllerServlet</servlet-name>
    <url-pattern>/category</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>>ControllerServlet</servlet-name>
    <url-pattern>/checkout</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>ControllerServlet</servlet-name>
    <url-pattern>cart</url-pattern>
</servlet-mapping>

对应于url模式的资源都放在WEB-INF / views目录中,当我运行任何页面时netbeans控制台说模块尚未部署,但是如果我从web中删除servlet配置代码。 xml,它运行正常,我不知道这里发生了什么,这里是servlet控制器

    @WebServlet(name = "ControllerServlet",loadOnStartup=1, urlPatterns = {"/category", "/addToCart", "/viewCart","/updateCart","/checkout","/purchase","/chooseLanguage","/cart"})
public class ControllerServlet extends HttpServlet {
  @Override
protected void doGet(HttpServletRequest request,HttpServletResponse response )
        throws ServletException,IOException{
//return the part of this request's url that calls servlet
String userPath=request.getServletPath();
if(userPath.equals("/category"))
{
//TODO: implement category request
}
else if(userPath.equals("/viewCart"))
{
//implement view cart request
}
else if(userPath.equals("/checkout")){
//implement checckout
}
else if(userPath.equals("/chooseLanguage")){
//language request
}
//Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path.
//A RequestDispatcher object can be used to forward a request to the resource or to include the resource in a response.
//The resource can be dynamic or static.
String url="/WEB-INF/Views" + userPath + ".jsp";
try{
request.getRequestDispatcher(url).forward(request, response);
}
catch(Exception ex)
{
    ex.printStackTrace();
}
}
 @Override
protected void doPost(HttpServletRequest request,HttpServletResponse response)
        throws IOException,ServletException{
String userPath=request.getServletPath();
if(userPath.equals("/addToCart"))
{
//add to cart
}
else if(userPath.equals("/updateCart"))
{
//update cartaction
}
else if(userPath.equals("/purchase"))
{
//purchase
    userPath="/confirmation";
}
String url="/WEB-INF/Views"+userPath+".jsp";
    //Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path.
//A RequestDispatcher object can be used to forward a request to the resource or to include the resource in a response.
//The resource can be dynamic or static.
try{
request.getRequestDispatcher(url).forward(request, response);

}
catch(Exception ex)
{
ex.printStackTrace();
}

}

}

没有页面可以运行

0 个答案:

没有答案