Struts2接收请求参数
2015-06-10 22:52
459 查看
HelloWorldAction.java
struts.xml
hello.jsp
或
http://localhost:8080/Struts2/hello/h1_work.action?id=11&name=zzzz
能得到浏览器显示:
public class HelloWorldAction { private Integer id; private String name; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String work() { return "success"; } public String execute() throws Exception { return "success"; } }
struts.xml
<?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> <constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="true" /> <constant name="struts.action.extension" value="do,action" /> <package name="he" namespace="/hello" extends="struts-default"> <action name="h1_*" class="com.zero.HelloWorldAction" method="{1}"> <result name="success">/WEB-INF/jsp/hello.jsp</result> </action> </package> </struts>
hello.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>My JSP 'hello.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> id=${id } <br/> name=${name } </html>访问:http://localhost:8080/Struts2/hello/h1_execute.do?id=11&name=zzzz
或
http://localhost:8080/Struts2/hello/h1_work.action?id=11&name=zzzz
能得到浏览器显示:
id=11 name=zzzz
相关文章推荐
- (JAVA)截取中英文混合字符串
- Java多线程基础(二)
- 指定Struts2处理的请求后缀
- [3] MQTT,mosquitto,Eclipse Paho---如何使用 Eclipse Paho MQTT工具来发送订阅MQTT消息?
- Struts2视图转发
- JavaWeb_Web开发入门
- spring4如何整合 hibernate4 配置详解
- 232_尚学堂_高淇_java300集最全视频教程_【GOF23设计模式】_建造者模式详解
- 小白心目中的Java抽象类(abstract class)
- java基础IO流 Properties类,打印流,合并流
- Spring IOC
- eclipse中查看快捷键
- java PropertyDescriptor 应用及源码分析
- MAC JDK版本切换
- java Introspector谈Java内省机制
- 黑马程序员---2015.6.10java学习笔记---软件--dos--JDK---while
- Java基础
- Java外观模式(Facade)
- 用数组实现栈(java语言实现)
- Spring Aop代理