Struts-if no class is available, actionsupport will be executed.

Source: Internet
Author: User

Create a project
Struts2101403
Add jar package
Commons-fileupload-1.3.jar
Commons-io-2.0.1.jar
Commons-lang3-3.1.jar
Freemarker-2.3.19.jar
Javassist-3.11.0.GA.jar
Ognl-3.0.6.jar
Struts2-core-2.3.15.1.jar
Xwork-core-2.3.15.1.jar
SRC
Create package
CN. jbit. strut2101403.web. Action
Create object class
@ Override
Public String execute () throws exception {
Return super.exe cute ();
}
Conf
Add struts. xml configuration file
<? 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>
<! -- Modify a topic -->
<Constant name = "struts. UI. Theme" value = "simple"> </constant>
<! -- Modify the struts request extension -->
<Constant name = "struts. Action. Extension" value = "do"> </constant>
<! -- Automatically load the Struts. xml file -->
<! -- <Constant name = "struts. configuration. xml. Reload" value = "true"> </constant> -->
<! -- Configure the development mode -->
<Constant name = "struts. devmode" value = "true"> </constant>
<Package name = "default" namespace = "/" extends = "struts-Default">
<Default-action-ref name = "defaultaction"> </default-action-ref>
<! --
If no class is available, actionsupport will be executed.
-->
<Action name = "noclassaction">
<Result name = "success">/WEB-INF/pages/success. jsp </result>
</Action>

<! --
Default action
-->
<Action name = "defaultaction" class = "cn. jbit. strut2101403.web. Action. defaultaction">
<Result>/WEB-INF/pages/Default. jsp </result>
</Action>

<Action name = "noclassaction1">
<Result name = "success">/WEB-INF/pages/success. jsp </result>
</Action>
</Package>
</Struts>
Web. xml
<Filter>
<Filter-Name> struts </filter-Name>
<Filter-class> org. Apache. struts2.dispatcher. Ng. Filter. strutsprepareandexecutefilter </filter-class>
</Filter>
<Filter-mapping>
<Filter-Name> struts </filter-Name>
<URL-pattern>/* </url-pattern>
</Filter-mapping>

Test

Create index. jsp
<% @ Page Language = "Java" Import = "Java. util. *" pageencoding = "UTF-8" %>
<% @ Taglib prefix = "S" uri = "/Struts-tags" %>
<%
String Path = request. getcontextpath ();
String basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/";
%>

<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
<Base href = "<% = basepath %>">

<Title> my JSP 'index. jsp 'starting page </title>
<Meta http-equiv = "Pragma" content = "no-Cache">
<Meta http-equiv = "cache-control" content = "no-Cache">
<Meta http-equiv = "expires" content = "0">
<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">
<Meta http-equiv = "Description" content = "this is my page">
<! --
<LINK rel = "stylesheet" type = "text/CSS" href = "styles.css">
-->
</Head>

<Body>
<A href = "$ {pagecontext. Request. contextpath}/noclassaction. Do"> noclassaction </a> <br/>
<A href = "$ {pagecontext. Request. contextpath}/noclassaction1.do"> noclassaction </a> <br/>
<A href = "$ {pagecontext. Request. contextpath}/noaction. Action"> request an action that is not configured </a> <br/>
</Body>
</Html>

Create a login, register, error page in webroot/WEB-INF/pages
Error. jsp
Logon Failed
Default. jsp
Default Page
Success. jsp
Noclassaction


This article from the "Su Yan" blog, please be sure to keep this source http://suyanzhu.blog.51cto.com/8050189/1564328

Struts-if no class is available, actionsupport will be executed.

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.