![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Struts2
文章平均质量分 69
刘利新西安
A MathJava fellow
展开
-
struts1 分页
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package com.vaannila;import java.util.ArrayList;/** * * @author eswar@vaannila.com */public转载 2013-10-15 14:21:09 · 682 阅读 · 0 评论 -
使用OGNL通过请求对象访问bean属性
action这个类里面,要有表单上对应的属性package roseindia.action;import javax.servlet.http.HttpServletRequest;import org.apache.struts2.interceptor.ServletRequestAware;import roseindia.model.StudentDetails;impor转载 2013-06-13 20:51:37 · 814 阅读 · 0 评论 -
通过struts2的配置文件访问jsp
把对jsp的请求绑定到strus2的系统中,这是一种值得推荐的方式。fuck me. anyone saw the problem: charset=uft-8,SEVERE: Error processing requestjava.lang.NullPointerExceptionat org.apache.catalina.connector.OutputBuffer.rea原创 2013-06-03 21:06:01 · 754 阅读 · 0 评论 -
今天把session设置成功了
package roseindia.action;import java.util.ArrayList;import java.util.List;import java.util.Map;import org.apache.struts2.interceptor.SessionAware;import com.opensymphony.xwork2.ActionSupport;转载 2013-06-12 20:17:19 · 524 阅读 · 0 评论 -
struts2的登录和退出
freshly debugged source:http://blog.csdn.net/weiyanghuadi/article/details/9081879SessionAware用的是依赖注入。而ActionContext.getContext().getSession()不是。不过,它们的作用是相同的,都是返回一个Map,这跟servlet API中的HttpSession不一样。转载 2013-06-13 05:56:40 · 3615 阅读 · 0 评论 -
struts2生成session的方法:ActionContext.getContext().getSession()
The original source code has a lot of bugs. The two sessions,one in jsp I made the following changes:success2.jsp<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncod原创 2013-06-13 07:25:11 · 2283 阅读 · 0 评论 -
使用OGNL获得session中的值
原文用ActionContext context = ActionContext.getContext();Map session = context.getSession();这样得不到session必须实现SessionAware接口,然后对Map session属性用setter,getter另外,表单中的所有元素都用struts2的标签,然后jsp页面的编码全设置成ut转载 2013-05-27 23:42:09 · 1131 阅读 · 0 评论 -
struts2使用annotation生成session
/** * @author Andrew Will */public class GenerateSessionData extends ActionSupport implements SessionAware { private static List messages = generateRandomMessages(); private static List users =转载 2013-06-08 06:14:04 · 597 阅读 · 0 评论 -
struts2类型转换
web.xml中要有以下条目 datePattern yyyy-MM-dd public class TypeConversionExample extends ActionSupport{ private static final long serialVersionUID = 1L; private String name; priva转载 2013-06-08 21:53:15 · 477 阅读 · 0 评论 -
Cannot instantiate the type Map
如果用第19行,就会出现上面错误。因为没有这样写:extends ActionSupport implements SessionAwarepackage liulixin.org;import java.util.HashMap;import java.util.Map;import com.opensymphony.xwork2.ActionSupport;public cl原创 2013-05-09 10:34:08 · 2669 阅读 · 0 评论 -
在jsp中设置由OGNL读取的属性
本文只有下面一个jsp文件,没有java类,也没有struts.xml,目的是熟悉OGNL的用法。<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>西安小升初 <% ActionContext.getContext().getSession()原创 2013-06-14 21:16:35 · 738 阅读 · 0 评论 -
EL表达式读表单参数
用struts2可以避免中文乱码<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>EL表达式 Hello ${param['username']}下面这种写法中文会有乱码<%@ page language="java" con原创 2013-06-05 23:25:17 · 818 阅读 · 0 评论 -
struts2拦截器
本文的拦截器部分是好的,但是session部分不对,这里有两个对的:http://blog.csdn.net/weiyanghuadi/article/details/8931820http://blog.csdn.net/weiyanghuadi/article/details/9050245本文把拦截器和sessionAware写在一起了,本来觉得DummyAction类简转载 2013-06-07 19:16:07 · 548 阅读 · 0 评论 -
struts2中的session到底是个什么东西
what the hell is Map session in Struts2. Anything to do with jsp session?提示空值java.lang.NullPointerExceptionWhen I get the session map using sessionaware interface, I get an empty map下面这个例子可以运行转载 2013-06-07 18:55:05 · 1105 阅读 · 0 评论 -
struts2中使用session
要注意,在Java类中,Map变量用的是m而到了jsp页面,都是用的session.For each Action class or a jsp visited by the same client, the controller injects the same map object, the controller creates a new map object for each clie转载 2013-05-15 19:02:28 · 777 阅读 · 0 评论 -
注意struts2的启动文件
如果web.xml中这样配置: index.html 而在根目录下没有index.html,而是index.jsp,那么,会出现下面错误:Struts has detected an unhandled exception: Messages: There is no Action mapped for namespace [/] and action na原创 2013-06-17 08:12:41 · 553 阅读 · 0 评论 -
登录页面的验证
在用户提交表单的时候,用struts2提供的机制,验证密码是否为空,用户名是否合乎规则。 public void validate() { if (getUserName().length() == 0) { addFieldError("userName", "UserName.required");转载 2013-06-16 00:05:06 · 690 阅读 · 0 评论 -
struts2与spring的整合
在web.xml中,注意比只用struts2多了一个监听器 struts2 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter org.springframework.web.context.ContextLoaderListener struts2 /* ja转载 2013-06-16 01:05:07 · 542 阅读 · 0 评论 -
不带struts2的纯OGNL的例子
pure OGNL example without struts2,for the benefit of your completely understanding it.public class User { private String name; public String getName() { return name; } pu原创 2013-06-15 04:24:12 · 511 阅读 · 0 评论 -
在struts2中如何获得session id
how to get session id in struts2首先,你要得到:How To Get The HttpServletRequest In Struts 2这样做:HttpServletRequest request = ServletActionContext.getRequest();import javax.servlet.http.*;import原创 2013-06-06 10:41:43 · 1994 阅读 · 0 评论 -
自动调用validate方法
index.jspZouYiGe /haha.jsp package liulixin;import com.opensymphony.xwork2.ActionSupport;public class test_validate extends ActionSupport { public String execute(){ return S原创 2013-06-06 03:59:39 · 650 阅读 · 0 评论 -
第一个用struts2处理中文的例子
index.jsp<% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";%>">My JSP 'inde转载 2013-05-15 21:35:56 · 491 阅读 · 0 评论 -
MySQL的字符集以及中文乱码问题
创建数据库:CREATE DATABASE IF NOT EXISTS liu_yan_ban2 default charset utf8 COLLATE utf8_general_ci; CREATE TABLE liuyan_temp( id int(6) NOT NULL auto_increment, url varchar(100) default '#', ip v原创 2013-05-15 20:50:17 · 1199 阅读 · 0 评论 -
struts2读mysql
create database if not exists struts2_mysql;use struts2_mysql;drop table if exists `user3333`;create table `user3333`(`id` int(11) not null auto_increment,`name` varchar(20) not null,`passwo转载 2013-05-28 17:38:33 · 670 阅读 · 0 评论 -
出现错误时的提示页面
package liulixin.org;import com.opensymphony.xwork2.ActionSupport;public class ErrorInfo extends ActionSupport{ public String CuoWu(){ addFieldError("SingleShowNoExist",getText("存在的就是合理的"));原创 2013-05-11 03:56:13 · 672 阅读 · 0 评论 -
表单元素与普通类的对应属性
你的前端页面如果有 这个,那么你的后台类就应该有 private String yourName;public String getYourName() { return yourName;} public void setYourName(String yourName) { this.yourName = yourName;}注意各处your翻译 2013-05-24 03:41:50 · 456 阅读 · 0 评论 -
在Jsp页面里面将Struts标签所取的值赋给一个字符串
请注意19行到25行<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>西安Java培训西安小升初 预览页面 名字:<struts2:property value="userName" /> Roll No. : <struts2:proper原创 2013-05-22 22:40:53 · 637 阅读 · 0 评论 -
struts2的第一个例子
比hello world好得多package action; import com.opensymphony.xwork2.ActionSupport; public class FirstAction extends ActionSupport{ private int operand1; private int operand2; public转载 2013-05-09 05:33:58 · 573 阅读 · 0 评论 -
判断用户是否登录的模拟
package liulixin.org;import com.opensymphony.xwork2.ActionSupport;public class LogInOrNotAction extends ActionSupport{ public String isLogin(){ if(1==1) return "nosir"; else return "yess原创 2013-05-09 06:44:26 · 542 阅读 · 0 评论 -
下拉列表与数组列表ArrayList的绑定
package liulixin.org;import java.util.ArrayList;import com.opensymphony.xwork2.ActionSupport;public class XiaLaAction extends ActionSupport { private ArrayList pairList; // 开始没写getter和setter,结原创 2013-05-08 23:15:54 · 745 阅读 · 0 评论 -
struts2用户界面之标注标签
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>西安Java培训西安小升初 文字标签 <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Str原创 2013-05-22 02:34:41 · 493 阅读 · 0 评论 -
不需要显式地声明tld路径了
struts2里不要再配置tag-lib,在struts-core包里面有tld文件的使用s标签,引入:这样就可以了。web.xml<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="ht转载 2013-05-07 23:54:46 · 740 阅读 · 0 评论 -
整站源码测试之一
最近从一个群里下载了一个“都市信息供求网”的源码,struts2+msql的。逐步测一下,以便学习。直接运行源码中的mysql脚本不行,中文部分输入不全。把sql脚本分成了几段,删除了一些版本信息,存成文本文件,可以了。CREATE DATABASE IF NOT EXISTS `db_cityinfo` DEFAULT CHARACTER SET utf8 ;USE `db_ci原创 2013-05-08 02:56:16 · 851 阅读 · 0 评论 -
通过Struts2在视图页面中获得get方法的返回值
public String getLiulixin() { return YES; } public String getNiMaLaGe() { return "骂了隔壁"; } <s:radio label="你喜欢绿蛋 and ham?" name="yourEggsAndHam" list="yesno" value="liulixin" />原创 2013-05-24 00:13:40 · 796 阅读 · 0 评论 -
iterator的用法
类的写法public String execute() { comboMeals = new ArrayList(); comboMeals.add("小吃 Plate"); comboMeals.add("正餐 Plate"); comboMeals.add("Colonel Chicken 组合"); comboMeals.add("上校汉堡"); combo转载 2013-05-24 23:53:24 · 467 阅读 · 0 评论 -
struts2读数据库
CREATE TABLE `struts_tutorial`.`login` ( `user` VARCHAR( 10 ) NOT NULL , `password` VARCHAR( 10 ) NOT NULL , `name` VARCHAR( 20 ) NOT NULL , PRIMARY KEY ( `user` )) ENGINE = InnoDB;INSE转载 2013-05-15 03:36:40 · 612 阅读 · 0 评论 -
竖直单选按钮
list.jsp NewFile.jsp package net.liulixin;import java.util.ArrayList;import java.util.List;import com.opensymphony.xwork2.ActionSupport;public class ListAction extends ActionSuppo转载 2013-05-28 19:08:25 · 714 阅读 · 0 评论 -
用struts2提取一个表中的所有记录
在普通类中,把读出的一条一条的记录放到一个list中,然后再在jsp中用迭代器iterator读出list的内容。治理了中文乱码,mysql和tomcat都是默认值的安装,没做任何字符集的特殊设置。<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>西安转载 2013-05-28 18:09:27 · 484 阅读 · 0 评论 -
struts2的表单
运行结果:<% Map checkState = new TreeMap(); checkState.put("1", "已审核"); checkState.put("0", "未审核"); checkState.put("all", "全部"); Map payforState = new TreeMap(); payforState.put("1", "已付费")转载 2013-05-14 11:39:53 · 510 阅读 · 0 评论 -
用ActionContext.getContext().getValueStack()获得值栈
value stack是一些对象的几何,最后放到这个集合中的元素是:Named ObjectsThese objects include #application, #session, #request, #attr and #parameters and refer to the corresponding servlet scopes以下代码治理了从表单到后台java,再到前台js转载 2013-05-27 21:43:27 · 3127 阅读 · 0 评论