I am using
- Eclipse 4.5.2
- Apache Tomcat 7.0.34
- Struts 2.5
When I run the project in Eclipse I get a 404 error I appreciate help on this issue.
404 Error:
Codes in my project are as below:
web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Struts 2 Web Application</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<!--
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
-->
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>welcome</welcome-file>
<welcome-file>login</welcome-file>
</welcome-file-list>
</web-app>
login.jsp
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
</head>
<body>
<h1>Struts 2 localization example</h1>
<s:form action="validateUser" namespace="/user">
<s:textfield key="global.username" name="username" />
<s:password key="global.password" name="password"/>
<s:submit key="global.submit" name="submit" />
</s:form>
<s:url var="localeEN" namespace="/" action="locale" >
<s:param name="request_locale" >en</s:param>
</s:url>
<s:url var="localezhCN" namespace="/" action="locale" >
<s:param name="request_locale" >zh_CN</s:param>
</s:url>
<s:url var="localeDE" namespace="/" action="locale" >
<s:param name="request_locale" >de</s:param>
</s:url>
<s:url var="localeFR" namespace="/" action="locale" >
<s:param name="request_locale" >fr</s:param>
</s:url>
<s:a href="%{localeEN}" >English</s:a>
<s:a href="%{localezhCN}" >Chinese</s:a>
<s:a href="%{localeDE}" >German</s:a>
<s:a href="%{localeFR}" >France</s:a>
</body>
</html>
welcome.jsp
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<body>
<h1>Struts 2 localization example</h1>
<h4>
<s:property value="username"/>
</h4>
</body>
</html>
struts.xml
<constant name="struts.custom.i18n.resources" value="global" />
<constant name="struts.devMode" value="true" />
<package name="user" namespace="/user" extends="struts-default">
<action name="login">
<result>pages/login.jsp</result>
</action>
<action name="validateUser" class="com.mkyong.user.action.LoginAction">
<result name="SUCCESS">pages/welcome.jsp</result>
<result name="input">pages/login.jsp</result>
</action>
</package>
<package name="default" namespace="/" extends="struts-default">
<action name="locale" class="com.mkyong.common.action.LocaleAction">
<result name="SUCCESS">user/pages/login.jsp</result>
</action>
</package>
<package name="emptyaction" namespace="/" extends="default">
<default-action-ref name="" />
<action name="">
<result type="redirect">/</result>
</action>
</package>
Structure My project structure is:
Aucun commentaire:
Enregistrer un commentaire