在WebSphere上使用Struts2部署动态Web JSP

问题描述:

我有一个使用struts2版本2.3.1.2的项目动态Web。 我想将此项目部署到WebSphere。但我得到的麻烦是:在WebSphere上使用Struts2部署动态Web JSP

[ERROR ] SRVE0293E: [Servlet Error]-[null]: com.ibm.ws.webcontainer.webapp.WebAppErrorReport: 

这是我的文件web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://java.sun.com/xml/ns/j2ee" 
xmlns:javaee="http://java.sun.com/xml/ns/javaee" 
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="WebApp_9" 
version="2.4"> 
<display-name>Struts2 Application</display-name> 
<filter> 
<filter-name>struts2</filter-name> 
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> 
</filter> 
<filter-mapping> 
<filter-name>struts2</filter-name> 
<url-pattern>/*</url-pattern> 
</filter-mapping> 
<welcome-file-list> 
<welcome-file>Login.jsp</welcome-file> 
</welcome-file-list> 
<servlet> 
<servlet-name>LoginAction</servlet-name> 
<servlet-class>net.viralpatel.struts2.action.LaunchServlet</servlet-class> 
<load-on-startup>1</load-on-startup> 
</servlet> 
</web-app> 

这是类LaunchServlet

public class LaunchServlet extends HttpServlet implements Servlet { 
public LaunchServlet() { 
    super(); 
} 
public void init(ServletConfig arg0) throws ServletException {  
    // this works around a bug in the websphere classloader. 
    super.init(arg0); 
    Dispatcher d = new Dispatcher(getServletContext(), new HashMap<String, 
String>());   
} 
} 

这是文件的struts.xml

<!DOCTYPE struts PUBLIC 
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" 
"http://struts.apache.org/dtds/struts-2.0.dtd"> 
<struts> 
<constant name="struts.enable.DynamicMethodInvocation" 
    value="false" /> 
<constant name="struts.devMode" value="false" /> 
<constant name="struts.custom.i18n.resources" 
    value="ApplicationResources" /> 

<package name="default" extends="struts-default" namespace="/"> 
    <action name="login" 
     class="net.viralpatel.struts2.action.LoginAction"> 
     <result name="success">Welcome.jsp</result> 
     <result name="error">Login.jsp</result> 
    </action> 
</package> 
</struts> 

我不知道如何解决它。

+0

不要遵循一些过时的网站。看看官方文档。 –

您应该使用servlet映射和新的支柱过滤

<servlet-mapping> 
    <servlet-name>LoginAction</servlet-name> 
    <url-pattern>/LoginAction</url-pattern> 
</servlet-mapping> 
<filter> 
    <filter-name>struts2</filter-name> 
    <filter-class> 
     org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter 
    </filter-class> 
</filter> 
<filter-mapping> 
    <filter-name>struts2</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 

再加入excludePattern常数struts.xml从Struts的执行排除servlet映射URL。

<constant name="struts.action.excludePattern" value="/LoginAction/?.*"/> 
+0

感谢您的回答。我试了一下,但得到了另一个错误: 错误404:没有为名称空间[/]和与上下文路径[/ Struts2_Hello_World]关联的动作名称[]映射操作。 我试着在tomcat 7.它的工作。但websphere它不工作! – Sang9xpro

+0

另一个错误应该发布在另一个问题。但是你的错误是众所周知的,有一个解决你的问题的答案https://*.com/a/40658006/573032 –