2017-10-10 96 views
0

我有一個使用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

不要遵循一些過時的網站。看看官方文檔。 –

回答

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://stackoverflow.com/a/40658006/573032 –