Struts2为我们提供了丰富的拦截器,而实现自定义拦截器也是容易的一件事。
拦截器必须是无状态的,原因是Struts2不能保证为每一个请求或者action创建一个实例,所以如果拦截器带有状态,会引发并发问题。
实际应用中处理权限问题是常见的,下面就以一个拦截器来判断处理用户是否登录而有权限去执行action的内容。
LoginInterceptor.java
package com.linuxsight.interceptor;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
public class L...
阅读全文
文件上传这个功能在项目应用是非常常见的,这节说说Struts2如何实现文件上传。
Struts2使用开源项目Apache Jakarta Commons FileUpload和内建的FileUploadInterceptor拦截器实现文件上传
下面介绍代码:
FileUploadAction
package com.linuxsight.action;
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionContext;
public class FileUploadAction {
private File upload;
private String uploadFileName;
private String uploadContentType;
priva...
阅读全文
本节记录了一些struts2的知识点。
1、设置开发调试
struts.properties
struts.devMode = true
添加struts2-config-browser-plugin-2.3.1.jar
地址访问:http://localhost:8080/struts2T1/config-browser/index.action
使用标签<s:debug/>显示
地址访问:
http://localhost:8080/struts2/linuxsight.action?debug=xml
http://localhost:8080/struts2/linuxsight.action?debug=console
2、在struts.properties更换struts2默认主题
struts.ui.theme=simple//主题设为simple,不会在生成多余的html代码
3、struts2运行时变量查找顺序
default.properties
strut...
阅读全文
本节介绍在ubuntu上开发的一个struts2应用。
新建一个web项目,利用myeclipse9.1给我们提供的struts2支持,搭建环境。
这里注意不要勾选多余的jar包,我们只需要core
myeclipse9.1集成的Sturts版本是struts2.2.1
代码如下:
web.xml
<?xml version=”1.0″ encoding=”UTF-8″?>
<web-app version=”3.0″
xmlns=”http://java.sun.com/xml/ns/javaee”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee
http://java.sun.com/x...
阅读全文
本系列文章带来的是在Ubuntu11.10下开发Struts2程序学习过程所记录的滴滴点点,当中所写的也许不能算是学习的好教程,但所涉及的知识点相信会对学习Struts2有一定的帮助。
首先是在Ubuntu11.10搭建开发环境,相信大部分开发者都是在XP下完成的,比较少涉及Linux平台,如果你是用Ubuntu系统的,那可以看看本节内容。
1、安装myeclipse(由于myeclipse已经自带了Tomcat,所以我们不需要再去下载Tomcat了。)
最新的myeclipse已经是myeclipse10了,不过我这里用的myeclipse9.1。
下载地址:http://www.linuxsight.com/blog/2525
安装方法:
linuxsight@linuxsight-ODM:...
阅读全文
这篇笔记放了N久了,我还是觉得放上来可以有个参考。
做了些许修改。。。。。
用了新版本的MyEclipse6.0.1(环境问题可能对开发环境有一定的影响,特别的框架开发SSH)做了简单的测试,果然添加的时候少了一个包,还好我从先前的项目拿过来就没事了
服务器已经换成是weblogic了,在MyEclipse6.0.1配置weblogic9.2
填写相关信息
D:\weblogic\bea
D:\weblogic\bea\weblogic92
weblogic
weblogic
D:\weblogic\bea\user_projects\domains\base_domain
AdminServer
D:\weblogic\bea\weblogic92\server\lib\weblogic.policy
注意JDK选择weblogi...
阅读全文
自从上回暑假做的项目,一个学期都没时间再去弄.
过年回来,把样子给变变. 先发个页面看看,自我感觉挺酷的…呵呵
整个系统采用三个框架做支撑,运行在tomcat,用sun的mysql,开发工具用eclipse
而下面选取了12有代表性的linux/unix操作系统(主要还是依照我个人爱好),各占一边.
用户中心参照了MLDN做了模仿,具体的还需要细化.
这几天对jQuery感兴趣,网上有很多插件,有很多很漂亮的效果
推荐一款插件 模仿macOS风格的按钮
http://icon.cat/software/iconDock/
里面写得很清楚了,我把它运用到项目底下12个图片上,效果就和mac系统下面那个按钮一样,超...
阅读全文
关于spring事务配置
这个问题从一开始困扰了我很久,主要是因为使用HibernateTemplate的时候发生‘readOnly‘的问题。之前查了很多资料,都说用spring事务配置可以解决,但之前我都一直没成功。昨天一试,有效果了。
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
&n...
阅读全文
记得之前被 session的问题困扰了很久,也不断遇到很多问题,自己也提出许多解决方案,认识在不断加深中….
我把笔记发上来
执行更新update操作时候出现的问题,后台采用hibernateTemplate操作
Write operations are not allowed in read-only mode (FlushMode.NEVER) – turn your Session into FlushMode.AUTO or remove ‘readOnly’ marker from transaction definition
OpenSessionInViewFilter在getSession的时候,会把获取回来的session的flush mode 设为FlushMode.NEVER。然后把该sessionFactory绑定到TransactionSynchronizat...
阅读全文
错误信息收集:
做hibernate表一对一的时候
Exception in thread "main" org.springframework.orm.hibernate3.HibernateSystemException: attempted to assign id from null one-to-one property: person; nested exception is org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property: person
org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property: person
原因是外键的问题,idcard依赖于person的pid 在插入的时候 &nb...
阅读全文
最后的部分是管理员操作这一部分倒没遇到什么大的问题,一般的问题都可以解决。到是在最后加个登陆验证的过滤器的时候,登陆之后的ID值在有的页面总传不过去,真奇怪。
用户管理|——列出所有用户|——修改用户积分|——删除用户问题管理|——删除问题|——推荐问题栏目管理|——添加|——删除|——修改|——列出管理员|——添加|——删除修改密码
这一部分的代码也没什么特别,所以也不贴出来了
无法删除中文用户?(暂且改为按ID删除)
java.lang....
阅读全文
接下来开发个人中心
个人中心包括内容:
1、 修改个人信息
2、 列出我提出的问题
3、 列出我回答过的问题
4、 列出被采纳的问题
分页大概的流程 从后台DAO去数据
public List queryByItem(int itemid, int currentPage, int lineSize)
throws Exception {
// TODO Auto-generated method stub
List all = null;
String hql = "FROM Question AS q WHERE q.itemid=?";
Query q = super.getSession().createQuery(hql);
q.setInteger(0, itemi...
阅读全文
2008-07-20 22:25:27,531 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] – Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
2008-07-20 22:25:27,609 INFO [org.springframework.jdbc.support.SQLErrorCodesFact
ory] – SQLErrorCodes loaded: [DB2, HSQL, MS-SQL, MySQL, Oracle, Informix, PostgreSQL, Sybase]
2008-07-20 22:26:48,437 WARN [org.hibernate.jdbc.ConnectionManager] – finalizingwith closed connection
2008-07-20 22:26:48...
阅读全文
来看下面2张表
插入几条测试数据
insert into item value(1,’JAVASE’,’1′);
insert into item value(2,’JAVAEE’,’2′);
insert into subitem(subname,itemid,subcode) value(‘IO流‘,’1′,’1′);
insert into subitem(subname,itemid,subcode) value(‘多线程‘,’1′,’2′);
insert into subitem(subname,itemid,subcode) value(‘socket’,’1′,’3′);
insert into subitem(subname,itemid,subcode) v...
阅读全文
如果出现mysql乱码问题 修改my.ini两处红色的地方gb2312
[client]port=3306[mysql]default-character-set=gb2312# SERVER SECTION# ———————————————————————-## The following options will be read by the MySQL Server. Make sure that# you have installed the server correctly (see above) so it reads this # file.#[mysqld]# The TCP/IP Port the MySQL Server will listen onport=3306#Path to installatio...
阅读全文










最新评论
这样安装需不需要先给w
xp果然不行.....
各位想在Linux装o
为什么我会卡在第八步啊,我都
我用的是笔记本电脑,无线网卡
谢谢 啊 第一次看你你的文
怎样解锁手机啊
怎样搞中文啊??