Problem with STRUTS2 encountered there is no action mapped for Namespaces/and action name

Source: Internet
Author: User
Tags i18n

In the initial configuration of struts, you encounter a similar problem with there is no action mapped for Namespace/and action name, many of which are caused by our carelessness, as summarized in the following workaround:

1, struts.xml file configuration error, which is one of the big reasons

DTD problem is no longer mentioned here, many online related posts, the problem here is mainly applicable to version 2.0 of the problem, pay attention to distinguish between 2.0 and 2.1, the recommendations are used 2.0
Next is the problem of encoding format, if you encounter Chinese garbled, remember to add

<span style= "FONT-SIZE:18PX;" ><constant name= "struts.i18n.encoding" value= "GBK" ></constant></span>

Most issues are in the package,

Extends's role is mainly used to inherit struts-default or other package, according to their own circumstances change, it is recommended not to miss out;

namespace do not spell mistakes, because in the project will be divided into separate each module, it is recommended in peacetime practice in the best in the namespace/module name , good distinction, if the usual practice can write/, in the interview directly write

<%=request.getcontextpath ()%>/index.action
In the package there is a relatively easy to overlook is the action in <result>/r1.jsp</result>will be easier to miss "/", in the Access action prompt the requested resource is not available. Mostly because of a leak/a little more careful
<span style= "FONT-SIZE:18PX;" ><?xml version= "1.0" encoding= "UTF-8"? ><! 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.i18n.encoding "value=" GBK "></constant>    <package name=" Actions "namespace="/actions "extends=" Struts-default ">        < Action name= "index" >            <result>/r1.jsp</result>        </action>    </package></ Struts></span>

2. Problems that are easy to appear in index.jsp

<span style= "FONT-SIZE:18PX;" ><%@ page language= "java" contenttype= "text/html; charset=gb18030 "    pageencoding=" GB18030 "%><%    String Context=request.getcontextpath ();    SYSTEM.OUT.PRINTLN (context);%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >

The problem here is mainly in the JSP storage location, attention to distinguish between eclipse and myeclipse, I am using ECLIPSEEE,JSP storage location webcontent, and Web-inf at the same level , This is also one of the important reasons for not visiting

It is advisable to add. Action when visiting.

3. 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/javaee" xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee/http Java.sun.com/xml/ns/javaee/web-app_2_5.xsd "id=" webapp_id "version=" 2.5 ">  <display-name>struts</ display-name>   <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>     <welcome-file-list>    <welcome-file> index.jsp</welcome-file>  </welcome-file-list>  </web-app>

It is best to copy the above filter, do not change the content, the problem may appear in <welcome-file-list>, because there is a index.html and index.htm in the originally generated Web. xml file, choose according to your own situation

The above is the experience, hope to help everyone ~ ~




Problem with STRUTS2 encountered there is no action mapped for Namespaces/and action name

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.