01:导包,web.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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"> <!-- 01:启动struts2框架 -->
<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>

  

02:编写action类

package com.self.action;
/**
* 02:写相应的处理方法
*/
public class HelloWorldAction { private String user;
private Integer id; //处理方法
public String helloworld(){
return "rehelloworld";
} public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
} public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} }

  

03:配置struts.xml

<?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>
<!-- 01:将.action访问,改为.do和.action -->
<constant name="struts.action.extension" value="do,action" />
<!-- 02:指定默认编码,相当于HttpServletRequest的setCharacterEncoding方法,也作用于freemarker、velocity的输出 -->
<constant name="struts.i18n.encoding" value="UTF-8" /> <include file="department.xml"/>
</struts>

  

04:配置department.xml

<?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>
<package name="dep" namespace="/department" extends="struts-default">
<!-- 用通配符*来指代方法名,{1}代表第一个通配符所代表的字段:这里代表方法 -->
<action name="hd_*" class="com.self.action.HelloWorldAction" method="{1}" >
<result name="rehelloworld">
/successhelloworld.jsp
</result>
</action>
</package>
</struts>

  

05:编写输入数据界面

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head> <title>显示</title>
</head> <!-- 第4步:显示 -->
<body>
<BR>
<BR>
<center>
<form action="department/hd_helloworld.do" method="post">
名:<input name="user" type="text">
<BR>
ID:<input name="id" type="text">
<BR>
<input type="submit" value="提交">
</form>
</center>
</body>
</html>

  

06:编写显示数据界面

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head> <title>显示</title>
</head> <!-- 第4步:显示 -->
<body>
<BR>
<BR>
<center>
user=${user}
<BR>
id=${id}
</center>
</body>
</html>

  

08:访问路径

http://localhost:8080/Struts2_01/seehelloworld.jsp

  

struts请求基本类型参数接收的更多相关文章

  1. Jquery Datatables 请求参数及接收参数处理

    Jquery Datatables 请求参数及接收参数处理 /** * Created by wb-wuyifu on 2016/8/9. */ /** * Created by wb-wuyifu ...

  2. vue axios 发送post请求,后端接收参数为null

    1首先检查自己的传参方式是否正确,我是传一个对象,没有问题,接口也触发了 2查了下资料说是 Content-Type的问题,设置为   'application/x-www-form-urlencod ...

  3. java中两种发起POST请求,并接收返回的响应内容的方式  (转)

    http://xyz168000.blog.163.com/blog/static/21032308201162293625569/ 2.利用java自带的java.net.*包下提供的工具类 代码如 ...

  4. SpringMvc 请求中日期类型参数接收一二事儿

    首先说明:以版本为Spring 4.3.0为测试对象: 开启<mvc:annotation-driven /> 测试场景一:请求中含有date属性,该类型为日期类型,SpringMvc采用 ...

  5. Struts框架(6)---action接收请求参数

    action接收请求参数 在web开发中,去接收请求参数来获得表单信息非常的常见,自己也总结整理了有关Struts2通过action接收请求参数的几种方法. Struts2 提供三种数据封装的方式: ...

  6. AngularJs的$http发送POST请求,php无法接收Post的数据解决方案

      最近在使用AngularJs+Php开发中遇到php后台无法接收到来自AngularJs的数据,在网上也有许多解决方法,却都点到即止.多番摸索后记录下解决方法:tips:当前使用的AngularJ ...

  7. struts请求源码的跟踪

    最近工作任务不是很紧,时间也不能白白浪费,以前常用的struts2框架源码没去了解过,所以就跟踪一下struts2的整个执行过程.由于本人也是抱着学习的态度来阅读掩码,若文章在表述和代码方面如有不妥之 ...

  8. PHP发送请求头和接收打印请求头

    一.发送请求头 //发送地址 $url = 'http://127.0.0.1/2.php'; //请求头内容 $headers = array( 'Authorization: '.$basic, ...

  9. angular的post请求,SpringMVC后台接收不到参数值的解决方案

    这是我后台SpringMVC控制器接收isform参数的方法,只是简单的打出它的值: @RequestMapping(method = RequestMethod.POST) @ResponseBod ...

随机推荐

  1. 设计模式:命令模式(Command)

    定   义:将一个请求封装为一个对象,从而使你可用不同的请求对客户进行参数化:对请求排列或者记录请求日志,以及支持可撤销的操作. 结构图: Command类: abstract class Comma ...

  2. 在RHEL5.2 64bit下编译安装log4cxx错误

    apache-log4cxx.0.10.0 依赖于apache-apr和apache-apr-utils两个包 先安装他们俩,然后编译log4cxx,发现make失败,错误如下 ronized.o . ...

  3. offset/client/scroll一些总结

    offset/client/scroll一些总结 1.offset 首先offset共有五个值 1.offsetParent 2.offsetTop 3.offsetLeft 4.offsetWidt ...

  4. 为什么一个object_id在dba_objects中为什么查不到记录?

    SQL> drop table test purge;SQL> create table test (id int,comments CLOB); SQL> select INDEX ...

  5. 设置tomcat的编码为utf-8

    <Connector URIEncoding="UTF-8" connectionTimeout="20000" port="8080" ...

  6. 由单例模式学到:volatile关键字

    MSDN上说: volatile 关键字指示一个字段可以由多个同时执行的线程修改. 声明为 volatile 的字段不受编译器优化的限制. 这样可以确保该字段在任何时间呈现的都是最新的值. volat ...

  7. 微信支付开发(4) 动态链接Native支付

    关键字:微信支付 微信支付v3 动态native支付 统一支付 Native支付 prepay_id 作者:方倍工作室原文: http://www.cnblogs.com/txw1958/p/wxpa ...

  8. 微信支付开发(11) Native支付

    关键字:微信公众平台 微信支付 Native原生支付作者:方倍工作室原文:http://www.cnblogs.com/txw1958/p/wxpay-native.html 由于微信支付接口更新,本 ...

  9. jquery实现"跳到底部","回到顶部"效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. 开发API文档相关问题(*.chm)

    在网上下了一个chm的文件,打开后只有目录,右侧不显示内容. 不知道是文件有问题,还是系统有问题. google了一下.解决了. 右键点击文件–属性 看到 最下面有一个提示 说是这个文件是来自其他计算 ...