struts请求基本类型参数接收
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请求基本类型参数接收的更多相关文章
- Jquery Datatables 请求参数及接收参数处理
Jquery Datatables 请求参数及接收参数处理 /** * Created by wb-wuyifu on 2016/8/9. */ /** * Created by wb-wuyifu ...
- vue axios 发送post请求,后端接收参数为null
1首先检查自己的传参方式是否正确,我是传一个对象,没有问题,接口也触发了 2查了下资料说是 Content-Type的问题,设置为 'application/x-www-form-urlencod ...
- java中两种发起POST请求,并接收返回的响应内容的方式 (转)
http://xyz168000.blog.163.com/blog/static/21032308201162293625569/ 2.利用java自带的java.net.*包下提供的工具类 代码如 ...
- SpringMvc 请求中日期类型参数接收一二事儿
首先说明:以版本为Spring 4.3.0为测试对象: 开启<mvc:annotation-driven /> 测试场景一:请求中含有date属性,该类型为日期类型,SpringMvc采用 ...
- Struts框架(6)---action接收请求参数
action接收请求参数 在web开发中,去接收请求参数来获得表单信息非常的常见,自己也总结整理了有关Struts2通过action接收请求参数的几种方法. Struts2 提供三种数据封装的方式: ...
- AngularJs的$http发送POST请求,php无法接收Post的数据解决方案
最近在使用AngularJs+Php开发中遇到php后台无法接收到来自AngularJs的数据,在网上也有许多解决方法,却都点到即止.多番摸索后记录下解决方法:tips:当前使用的AngularJ ...
- struts请求源码的跟踪
最近工作任务不是很紧,时间也不能白白浪费,以前常用的struts2框架源码没去了解过,所以就跟踪一下struts2的整个执行过程.由于本人也是抱着学习的态度来阅读掩码,若文章在表述和代码方面如有不妥之 ...
- PHP发送请求头和接收打印请求头
一.发送请求头 //发送地址 $url = 'http://127.0.0.1/2.php'; //请求头内容 $headers = array( 'Authorization: '.$basic, ...
- angular的post请求,SpringMVC后台接收不到参数值的解决方案
这是我后台SpringMVC控制器接收isform参数的方法,只是简单的打出它的值: @RequestMapping(method = RequestMethod.POST) @ResponseBod ...
随机推荐
- 【nodejs】使用Node.js实现REST Client调用REST API
最近在产品中开发基于REST的API接口,结合自己最近对Node.js的研究,想基于它开发一个REST Client做测试之用. 通过初步研究,Node.js开发HTTP Client还是挺方便的. ...
- 【转】MySQL USE NAMES 'UTF8'
先说MySQL的字符集问题.Windows下可通过修改my.ini内的 # CLIENT SECTION [mysql] default-character-set=utf8 # SERVER SEC ...
- JNI字段描述符-Java Native Interface Field Descriptors
一.JNI字段描述符 "[I" --- int[] "[[[D" --- double[][][] 如果以一个L开头的描述符,就是类描述符,它后紧跟着类的字符 ...
- WPF绑定Model的实例对象
创建一个用户控件 1. behindcode指定this.DataContext=XXViewModel 2. "{Binding DataContext.EditModel.MId,Rel ...
- JS-面向对象-封装
--参考文献: --http://www.ruanyifeng.com/blog/2010/05/object-oriented_javascript_encapsulation.html --js面 ...
- div滑入与滑出
html <div class="pop_tit"> <span class="p_tit1" title="大连未来城LECITY ...
- bootstrap响应式布局简单实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- saltstack之(九)配置管理源码部署Nginx
场景:rpm包安装的nginx服务,无法满足定制模块的需求,故线上环境使用nginx源码进行安装.本片文章详细介绍如何使用saltstack的配置管理功能实现nginx软件的源码安装. 下载源码:pc ...
- [logstash-input-file]插件使用详解(转)
最小化的配置文件 在Logstash中可以在 input{} 里面添加file配置,默认的最小化配置如下: 1 2 3 4 5 6 7 8 9 10 11 input { file ...
- winston日志管理2
上次讲到 Exceptions 例外 Handling Uncaught Exceptions with winston 使用winston处理未捕获的异常(这个如果对于异步,我不是很喜欢用) 使用 ...