Struts2 2.3.30版本的HelloWorld简单例子

 这个是struts.xml配置:只是简单的配置了<action>的name属性,以及<result>指向页面(/WEB-INF/pages/input.jsp)

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
	"http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>

    <package name="helloWord" extends="struts-default">

        <action name="product-input">
            <result>/WEB-INF/pages/input.jsp</result>
        </action>
    </package>

</struts>

下面的这个是web.xml配置信息 ,只需要将Struts2下载的文件中的web.xml中的部分扣下来即可!

<?xml version="1.0" encoding="UTF-8"?>

<web-app id="starter" version="2.4"
         xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <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>
</web-app>

下面的是/WEB-INF/pages下的input.jsp页面

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
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 'input.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>
<!--输入文本框以及提交按钮-->
    <form action="product-save.action" method="post">
 	ProductName:<input type="text" name="productName"/><br/>
 	ProductDesc:<input type="text" name="productDesc"/><br/>
  	ProductPrice:<input type="text" name="productPrice"/><br/>
  	<input type="submit" value="submit"/>
  	</form>
  </body>
</html>

再导入相应的jar包

就可以实现Struts2的简单例子了(如图)

 

转载于:https://my.oschina.net/ZYLzzz/blog/738858

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
antlr-2.7.2.jar, aopalliance-1.0.jar, asm-3.3.jar, asm-commons-3.3.jar, asm-tree-3.3.jar, builder-0.6.2.jar, classworlds-1.1.jar, commons-beanutils-1.8.0.jar, commons-chain-1.2.jar, commons-collections-3.2.2.jar, commons-digester-2.0.jar, commons-fileupload-1.3.2.jar, commons-io-2.2.jar, commons-lang-2.4.jar, commons-lang3-3.2.jar, commons-logging-1.1.3.jar, commons-validator-1.3.1.jar, core-0.6.2.jar, dwr-1.1.1.jar, ezmorph-1.0.6.jar, freemarker-2.3.22.jar, google-collections-1.0.jar, google-gxp-0.2.4-beta.jar, guava-r09.jar, jackson-core-asl-1.9.2.jar, jackson-mapper-asl-1.9.2.jar, javassist-3.11.0.GA.jar, jcl-over-slf4j-1.5.8.jar, json-lib-2.3-jdk15.jar, juli-6.0.18.jar, mvel2-2.0.11.jar, ognl-3.0.19.jar, org.apache.felix.framework-4.0.3.jar, org.apache.felix.main-4.0.3.jar, org.apache.felix.shell-1.4.3.jar, org.apache.felix.shell.tui-1.4.1.jar, org.osgi.compendium-4.0.0.jar, org.osgi.core-4.1.0.jar, oro-2.0.8.jar, oval-1.31.jar, plexus-container-default-1.0-alpha-10.jar, plexus-utils-1.2.jar, sitemesh-2.4.2.jar, slf4j-api-1.7.12.jar, spring-aop-3.0.5.RELEASE.jar, spring-asm-3.0.5.RELEASE.jar, spring-beans-3.0.5.RELEASE.jar, spring-context-3.0.5.RELEASE.jar, spring-core-3.0.5.RELEASE.jar, spring-expression-3.0.5.RELEASE.jar, spring-test-3.0.5.RELEASE.jar, spring-web-3.0.5.RELEASE.jar, struts-core-1.3.10.jar, struts2-cdi-plugin-2.3.30.jar, struts2-codebehind-plugin-2.3.30.jar, struts2-config-browser-plugin-2.3.30.jar, struts2-convention-plugin-2.3.30.jar, struts2-core-2.3.30.jar, struts2-dojo-plugin-2.3.30.jar, struts2-dwr-plugin-2.3.30.jar, struts2-embeddedjsp-plugin-2.3.30.jar, struts2-gxp-plugin-2.3.30.jar, struts2-jasperreports-plugin-2.3.30.jar, struts2-javatemplates-plugin-2.3.30.jar, struts2-jfreechart-plugin-2.3.30.jar, struts2-jsf-plugin-2.3.30.jar, struts2-json-plugin-2.3.30.jar, struts2-junit-plugin-2.3.30.jar, struts2-osgi-admin-bundle-2.3.30.jar, struts2-osgi-demo-bundle-2.3.30.jar, struts2-osgi-plugin-2.3.30.jar, struts2-oval-plugin-2.3.30.jar, strut

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值