简体   繁体   English

在我的JSP中映射servlet

[英]Mapping a servlet in my JSP

I have Java EE application which has a WAR file and an EJB file. 我有Java EE应用程序,该应用程序具有WAR文件和EJB文件。 The WAR file contains my jsps/html and my EJB contains my servlets/beans and EJB. WAR文件包含我的jsps / html,而我的EJB包含我的servlet / bean和EJB。 I try to call my servlet in one of my jsp pages, but it cant find it. 我尝试在我的一个jsp页面中调用我的servlet,但是找不到它。 The file im looking for is Authenticate. 我正在寻找的文件是Authenticate。 Its located in my EJB file so i figure the path for it would be 它位于我的EJB文件中,所以我想出它的路径是

action="../../EJBShoppingCart-ejb/build/classes/Servlet/Authenticate

I played around with URL, modifying it by taking taking away build or classes and a bunch of other ways.... my servlet has the @WebServlet(name = "Authenticate", urlPatterns = {"/Authenticate"}) annotation. 我试着使用URL,通过删除构建或类以及其他方法来对其进行修改。...我的servlet具有@WebServlet(name =“ Authenticate”,urlPatterns = {“ / Authenticate”})批注。

I know I can transfer all of my files from my EJB file to my WAR file and I think that would solve the problem. 我知道我可以将所有文件从EJB文件传输到WAR文件,并且我认为这可以解决问题。 But is there a way to map it correctly? 但是有没有办法正确地映射它?

 urlPatterns = {"/Authenticate"} 

So, it's mapped on an URL pattern of /Authenticate . 因此,它映射到/Authenticate的URL模式。 Assuming that your server runs on localhost:8080 and the webapp context name is myapp and the /WEB-INF/web.xml is conform Servlet 3.0 spec, then you can access it by http://localhost:8080/myapp/Authenticate 假设您的服务器在localhost:8080上运行,并且webapp上下文名称为myapp/ WEB-INF / /WEB-INF/web.xml符合Servlet 3.0规范,那么您可以通过http:// localhost:8080 / myapp / Authenticate访问它


I'm only not entirely sure whether an @WebServlet class inside an EJB would ever be located and loaded by the servletcontainer. 我不完全确定EJB @WebServlet是否可以找到并加载EJB内部的@WebServlet类。 Servlets usually go in WAR and end up in /WEB-INF/classes . Servlet通常进入WAR并以/WEB-INF/classes结尾。 Inside a JAR in /WEB-INF/lib is definitely possible, it has only to contain a Servlet 3.0 compatible /META-INF/web.xml /WEB-INF/lib的JAR内肯定是可能的,它仅包含与Servlet 3.0兼容的/META-INF/web.xml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM