- 浏览: 951040 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (423)
- mysql (37)
- hibernate (3)
- struts (9)
- spring (33)
- dom4j (2)
- junit (0)
- exception (1)
- 随笔杂谈 (12)
- google app engine (1)
- XMPP (1)
- OAuth安全授权 (1)
- 版本控制 (8)
- 心情感悟 (0)
- core java (19)
- log4j (7)
- jquery (12)
- javascript (10)
- 网站性能优化及工具 (11)
- 服务器架设配置等 (38)
- EXT (4)
- 正则表达式 (5)
- 日志统计分析 (2)
- htmlparse (4)
- httpclient (5)
- java随笔 (5)
- dhtmlxtree (1)
- freemarke (5)
- memcached (6)
- javamail (5)
- Linux命令 (10)
- 应用监控cpu web jdbc等 (4)
- jmagick (9)
- 第三方缓存策略 (9)
- ORM (2)
- hadoop (2)
- 大数据量处理 (8)
- 经典 (1)
- 权限设计 (1)
- andriod (1)
- mybatis (12)
- redis (24)
- 数据结构_算法 (5)
- 分布式系统 (1)
- php (1)
- 网络编程 (3)
- 服务器部署 (3)
- ios (2)
- IM (23)
- mina (1)
- 视讯和语音 (1)
- 代码生成 (1)
- 架构 (4)
- 建模工具 (1)
- oracle (4)
- solr (10)
- 构建工具 (7)
- html5 (1)
- nginx (5)
- css (1)
- 大数据-分布式 (2)
- 设计模式 (2)
- mq (2)
- jvm调优 (8)
- 并发编程 (2)
- 搜索引擎 (1)
- UML (2)
最新评论
-
天使建站:
jquery获取网页里多选框checkbox选中项的值的方法及 ...
JS jQuery分别获取选中的复选框值 -
abao1:
发现一个小问题 sortAndSave方法中的for循环 第二 ...
完整java实现外部排序 -
西巴拉古呀那:
Kafka分布式消息系统实战(与JavaScalaHadoop ...
消息系统kafka介绍 -
kafodaote:
Kafka分布式消息系统实战(与JavaScalaHadoop ...
消息系统kafka介绍 -
成大大的:
Kafka分布式消息系统实 ...
消息系统kafka介绍
WEB-INF/applicationContext.xml
Java代码
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="dataSource" name="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/db?useUnicode=true&characterEncoding=UTF-8"/>
<property name="user" value="root" />
<property name="password" value="root" />
<property name="maxPoolSize" value="50" />
<property name="minPoolSize" value="1" />
<property name="initialPoolSize" value="1" />
<property name="maxStatements" value="0"/>
<property name="maxIdleTime" value="20" />
</bean>
<bean id="sessionFactory" name="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>model/User.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.use_sql_comments">false</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.jdbc.batch_size">20</prop>
</props>
</property>
</bean>
<bean id="transactionManager" name="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="transactionInterceptor" name="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="BeanNameAutoProxyCreator" name="BeanNameAutoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>mgr</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
<bean id="mgr" name="mgr" class="service.UserManagerImpl">
<property name="userDAO" ref="userDAO" />
</bean>
<bean id="userDAO" name="userDAO" class="dao.user.UserDAOHibernate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>
WEB-INF/web.xml
Java代码
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<!-- 用于初始化Spring容器的Listener -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true </param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>openSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>openSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
model.User.java
Java代码
package model;
public class User
{
private int Id;
private String username;
private String password;
public int getId()
{
return Id;
}
public void setId(int id)
{
Id = id;
}
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username = username;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
}
model/User.hdm.xml
Java代码
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-access="field" package="model">
<class name="User" table="admin">
<id name="Id" column="Id">
<generator class="identity" />
</id>
<property name="username" column="username" not-null="true" generated="never" lazy="false" unique="true"/>
<property name="password" column="password" not-null="true" generated="never" lazy="false" />
</class>
</hibernate-mapping>
login.jsp
Java代码
<%@ page language="java" import="java.util.*"
contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@taglib prefix="sx" uri="/struts-dojo-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<script type="text/javascript">
function refresh()
{
document.getElementById("authImg").src = "authImg?d=" + new Date().getTime();
}
</script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<sx:head/>
<title><s:text name="%{getText('loginPage')}" /></title>
</head>
<body>
<div style="color: red">
<s:actionerror/>
</div>
<s:form action="Login" method="post" name="form" onsubmit="return validate(document.form)">
<s:textfield label="%{getText('username')}" name="username" value="" cssStyle="width:150px;" />
<s:password label="%{getText('password')}" name="password" value="" cssStyle="width:150px;" />
<s:textfield label="%{getText('vercode')}" name="vercode" value="" cssStyle="width:150px;" />
<s:submit value="%{getText('login')}"/>
</s:form>
验证码如图:<img src="authImg" id="authImg"/>看不清?<a href="#" onClick="refresh()">单击此处刷新</a>
</body>
</html>
action.LoginAction.java
Java代码
package action;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionContext;
public class LoginAction extends BaseAction
{
private static final long serialVersionUID = 1L;
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username = username;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
public String getVercode()
{
return vercode;
}
public void setVercode(String vercode)
{
this.vercode = vercode;
}
@SuppressWarnings("unchecked")
public String execute() throws Exception
{
Map session = ActionContext.getContext().getSession();
String ver = (String)session.get("authImg");
if (ver.equals(vercode))
{
int userId = mgr.loginValid(username,password);
if (userId > 0)
{
return SUCCESS;
}
else
{
addActionError(getText("noMatch"));
}
}
else
{
System.out.println("0k3");
addActionError(getText("vercodeErr"));
}
return "failure";
}
private String username;
private String password;
private String vercode;
}
UserDAOHibernate.java
Java代码
package dao.user;
import java.util.List;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import model.User;
public class UserDAOHibernate extends HibernateDaoSupport implements UserDAO
{
@SuppressWarnings("unchecked")
public User findUserByNameAndPass(String username , String password)
{
List ul = null;
try
{
[color=red]ul = getHibernateTemplate().find("from User au where au.username = ? and au.password = ?" ,new String[]{username,password});[/color]
} catch(DataAccessException e)
{
System.out.println("数据访问异常");
e.printStackTrace();
}
System.out.println(ul.size());
if (ul != null && ul.size() >= 1)
{
return (User)ul.get(0);
}
return null;
}
@SuppressWarnings("unchecked")
public User findUserByName(String username)
{
[color=red] List ul = getHibernateTemplate().find("from User au where au.username = ?" ,username);[/color]
if (ul != null && ul.size() >= 1)
{
return (User)ul.get(0);
}
return null;
}
@Override
public User get(int id)
{
return (User)getHibernateTemplate().get(User.class, id);
}
}
问题描述,1.验证码不显示,2.但是后台能发现6位验证码,当正确的用户名,密码,和后台的验证码后,jsp页面出现:
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.reflect.InvocationTargetException
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:440)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:279)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:163)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:249)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:148)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:93)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:128)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:104)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:148)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:128)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:468)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:102)
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:174)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
控制台出现:
12:16:11,779 DEBUG SessionImpl:248 - opened session at timestamp: 12527289717
12:16:12,193 DEBUG JDBCTransaction:82 - begin
12:16:12,194 DEBUG ConnectionManager:444 - opening JDBC connection
12:16:12,197 DEBUG JDBCTransaction:87 - current autocommit status: true
12:16:12,200 DEBUG JDBCTransaction:90 - disabling autocommit
12:16:12,469 DEBUG JDBCTransaction:186 - rollback
12:16:12,471 DEBUG JDBCTransaction:227 - re-enabling autocommit
12:16:12,475 DEBUG JDBCTransaction:197 - rolled back JDBC Connection
12:16:12,476 DEBUG ConnectionManager:325 - transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
12:16:12,480 DEBUG ConnectionManager:464 - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
12:16:12,480 DEBUG ConnectionManager:325 - transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
非常感谢大家。。。。。
问题补充:
liyaxi
现在异常没了,但是还是无法显示验证码图片
我的所有action都是默认命名空间,并且没有重命名的action
另外我生成图片的类是:
Java代码
package authImg;
import java.io.*;
import java.awt.*;
import java.awt.image.*;
import java.util.*;
import javax.imageio.*;
import javax.imageio.stream.ImageOutputStream;
public class AuthImg
{
private static final long serialVersionUID = 1L;
//设置图形验证码中字符串的字体和大小
private ByteArrayInputStream image;//图像
private String str;//验证码
public AuthImg()
{
init();
}
/*
* 取得AuthImg实例
*/
public static AuthImg Instance(){
return new AuthImg();
}
/*
* 取得验证码图片
*/
public ByteArrayInputStream getImage()
{
return this.image;
}
/*
* 取得图片的验证码
*/
public String getString()
{
return this.str;
}
/*
* 生成随机颜色
*/
private Color getRandColor(int fc, int bc)
{
Random random = new Random();
if (fc > 255)
fc = 255;
if (bc > 255)
bc = 255;
int r = fc + random.nextInt(bc - fc);
int g = fc + random.nextInt(bc - fc);
int b = fc + random.nextInt(bc - fc);
return new Color(r, g, b);
}
/*
* 生成服务器响应的服务方法
*/
public void init()
{
int width = 100, height = 18;
//生成一张新图片
BufferedImage image = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
//在图片中绘制内容
Graphics g = image.getGraphics();
Random random = new Random();
g.setColor(getRandColor(200, 250));
g.fillRect(1, 1, width - 1, height - 1);
//设定背景色
g.setColor(new Color(102, 102, 102));
g.drawRect(0, 0, width - 1, height - 1);
g.setFont(new Font("Arial Black", Font.PLAIN, 16));
//随机生成线条,让图片看起来更加杂乱
g.setColor(getRandColor(160, 200));
for (int i = 0; i < 155; i++)
{
int x = random.nextInt(width - 1);
int y = random.nextInt(height - 1);
int xl = random.nextInt(6) + 1;
int yl = random.nextInt(12) + 1;
g.drawLine(x, y, x + xl, y + yl);
}
for (int i = 0; i < 70; i++)
{
int x = random.nextInt(width - 1);
int y = random.nextInt(height - 1);
int xl = random.nextInt(12) + 1;
int yl = random.nextInt(6) + 1;
g.drawLine(x, y, x - xl, y - yl);
}
//用于保存系统生成的随机字符串
StringBuffer sRand = new StringBuffer(6);
for (int i = 0; i < 6; i++)
{
String tmp = getRandomChar();
sRand = sRand.append(tmp);
//将系统生成的随机字符添加到图形验证码图片上
g.setColor(new Color(20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110)));
g.drawString(tmp, 15 * i + 10, 15);
}
//赋值验证码
this.str = sRand.toString();
g.dispose();
ByteArrayInputStream input = null;
ByteArrayOutputStream output = new ByteArrayOutputStream();
//输出图形验证码图片
try
{
ImageOutputStream imageOut = ImageIO.createImageOutputStream(output);
ImageIO.write(image, "bmp", imageOut);
imageOut.close();
input = new ByteArrayInputStream(output.toByteArray());
}catch(Exception e){
System.out.println("验证码图片产生出现错误:" + e.toString());
}
//赋值图像
this.image = input;
}
/*
* 生成随机字符
*/
private String getRandomChar()
{
int rand = (int) Math.round(Math.random() * 2);
long itmp = 0;
char ctmp = '\u0000';
switch(rand)
{
//生成大写字母的情形
case 1:
itmp = Math.round(Math.random() * 25 + 65);
ctmp = (char) itmp;
return String.valueOf(ctmp);
//生成小写字母的情形
case 2:
itmp = Math.round(Math.random() * 25 + 97);
ctmp = (char) itmp;
return String.valueOf(ctmp);
//生成数字的情形
default:
itmp = Math.round(Math.random() * 9);
return String.valueOf(itmp);
}
}
}
产生图片的action是
Java代码
package action;
import java.io.ByteArrayInputStream;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import authImg.AuthImg;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class CreateCodeImgAction extends ActionSupport
{
private static final long serialVersionUID = 1L;
public void setInputStream(ByteArrayInputStream inputStream)
{
this.inputStream = inputStream;
}
public ByteArrayInputStream getInputStream()
{
return inputStream;
}
public String execute() throws Exception
{
HttpServletResponse response = ServletActionContext.getResponse();
//阻止生成页面被缓存,保证每次重新生成随机验证码
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Cache-Control", "no-store");
response.setDateHeader("Expires", 0);
response.setContentType("image/jpeg");
AuthImg authImg = AuthImg.Instance();
// 取得带有随机字符串的图片
setInputStream(authImg.getImage());
// 取得随机字符串放入HttpSession
System.out.println(authImg.getString());
ActionContext.getContext().getSession().put("authImg", authImg.getString());
return SUCCESS;
}
private ByteArrayInputStream inputStream;
}
struts.xml片段
Java代码
<package name="non-authority" extends="struts-default">
<action name="Login" class="action.LoginAction">
<result name="success">/spread/spread1.jsp</result>
<result name="failure">/login.jsp</result>
</action>
<action name="authImg" class="action.CreateCodeImgAction">
<result type="stream">
<param name="contentType">image/bmp</param>
<param name="inputName">inputStream</param>
</result>
<result name="success">login.jsp</result>
</action>
</package>
-------
2009-09-14 liyaxi (中级程序员)
<action name="authImg" class="action.CreateCodeImgAction">
<result type="stream">
<param name="contentType">image/bmp</param>
<param name="inputName">inputStream</param>
</result>
<result name="success">login.jsp</result>
</action>
把这个<result name="success">login.jsp</result> 删除掉就可以了,
最好把, image/bmp 改为 image/jpeg
把这个也改了 ImageIO.write(image, "bmp", imageOut); --- ImageIO.write(image, "jpeg", imageOut);
其实 是人最难发现自己的代码错误的。 你的思路很好, 我已经在我的机子上测试了,
没问题。 我以前只用下边的。
Xml代码
<result type="stream">
<param name="contentType">image/peg</param>
<param name="inputName">inputStream</param>
</result>
做下载用。 楼住举一反三 ,触类旁通。 在咱们论坛里有这篇文章 , 题目:struts2下实现了图片验证码,[url] http://tmq.iteye.com/blog/286022 [/url] , 希望对你有帮助。
发表评论
-
struts.xml
2010-09-16 17:38 738<?xml version="1.0" ... -
struts2配合log4j打印异常栈信息
2010-07-06 11:32 7717struts2配合log4j打印异常栈信息 关于配置s ... -
struts2小结
2010-01-16 15:09 1057Struts2使用OGNL进行类型 ... -
struts2
2010-01-16 15:01 11181:在action中定义的变量 ... -
BO层思想
2010-01-09 11:56 2347关于BO层的设计思想,自我理解 创建一个BO层的对象用于重组 ... -
struts2<s:if >标签进一步深入判断集合中对象属性值问题
2010-01-09 11:10 5520<s:iterator id="user&q ... -
struts2中的OGNL
2009-11-17 17:30 1889Struts2中的标签大量用到了OGNL表达式,于是做了一 ... -
strut2表单验证
2009-04-09 14:19 1537方式一: Action 继承ActionSupport 覆盖p ...
相关推荐
Struts2是一个强大的MVC(模型-视图-控制器)框架,广泛应用于Java Web开发中。在Struts2中,Action是核心组件之一,它负责处理用户的请求,并将业务逻辑的结果返回给视图进行展示。本实例将深入探讨在基于用户登录...
免责声明:资料部分来源于合法的互联网渠道收集和整理,部分自己学习积累成果,供大家学习参考与交流。收取的费用仅用于收集和整理资料耗费时间的酬劳。 本人尊重原创作者或出版方,资料版权归原作者或出版方所有,...
Struts2是一个非常流行的Java Web框架,用于构建和维护可扩展、模块化且易于管理的企业级应用程序。在网站运营中,了解网站访问总人数及点击率是至关重要的,这可以帮助我们评估网站的受欢迎程度,优化用户体验,...
2. `<s:actionerror>`标签:这个标签用于显示所有非字段相关的错误,如验证码错误等。只需将其放在表单内,它会自动收集并显示所有全局错误: ```jsp 用户名"/> 密码"/> 登录"/> ``` 3. OGNL(Object-...
- **表单提交**:使用HTML表单收集用户输入,Struts2通过Action进行处理。 - **会话管理**:登录成功后,通常会将用户信息存储在HttpSession中,以保持登录状态。 5. **文件上传与下载**: - **Commons ...
2. **ActionForm** - 表单数据的载体,它对应于JSP页面中的表单字段,用来收集和验证用户输入。 **五、数据库操作** 在用户注册过程中,通常需要将用户信息存储到数据库。这可以通过JDBC或者ORM框架如Hibernate来...
### Struts2框架实现留言板系统知识点详解 #### 一、项目背景与目标 本课程报告主要介绍了使用Struts2框架开发的一款留言板应用。该应用旨在为用户提供一个方便快捷的留言交流平台,支持用户登录、注册、发布留言...
Struts是Apache软件基金会下的一个开源项目,是一个基于MVC(Model-View-Controller)设计模式的Java Web应用框架。这个框架的主要目的是使开发者能够更有效地构建可维护、可扩展和易于测试的Web应用程序。在"struts...
8. **视图层**:通常,登录注册页面由JSP(JavaServer Pages)或HTML+JS+CSS实现,结合Struts2的标签库(如s:form, s:textfield等)来展示和收集用户输入。 9. **测试**:项目可能包含JUnit测试用例,用于验证...
8.有全文检索工具类包含索引的创建、查询等,自动分页Bean,Excel读取/导出等功能、汉字转拼音,MD5加密,加密解密,图片转字符、字符转图片,IP检查,拦截器权限拦截,Struts2Utils类,Spring3Utils类,轻松搞定...
2. **Struts2框架**:Struts2是Apache软件基金会的一个开源项目,它是基于MVC设计模式的Web应用框架,提供了一种组织应用代码的方式,使得开发者可以更有效地处理HTTP请求和响应。 3. **用户登录与注册**:这是所有...
在给定的"java开发jar包"主题中,我们可以看到涉及多个库和框架的文件,包括ehcache、hibernate、json-lib、mybatis、spring、SSH(Struts2、Spring、Hibernate集成)、struts2以及json处理。这些都代表了Java开发中...
2009-03-10 11:13 377530 94291 常见的专业问题解决办法\struts验证码 - Struts - Java - JavaEye论坛.mht 2007-10-20 11:27 427008 296205 常见的专业问题解决办法\swing程序设计.doc 2007-12-25 20:21 1504314 ...
Struts1的ActionForm可以收集表单数据,并通过ActionServlet进行校验和处理。 3. **个人信息修改**:注册后,用户可修改自己提交的信息,如更新邮箱或修改密码。Struts1通过ActionForm对象传递修改后的数据,再次...
本主题将深入探讨如何使用SSH2(Struts2、Spring、Hibernate)框架来实现注册功能以及对数据库进行简单增删改查操作。SSH2是Java web开发中常用的三大框架组合,它们各自负责不同的职责:Struts2处理MVC模式中的视图...
STRUTS框架通过ActionForm对象收集这些数据,然后由后台服务处理存储。同样,用户在已有的话题下发表回复,也是通过类似的方式实现。 **3. 注销登录:** 用户在完成操作后可能需要注销登录,这通常是一个简单的清理...
在这个名为“demo.rar”的压缩包文件中,我们找到了一个基于Java技术实现的SSH(Spring、Struts2、Hibernate)框架的示例应用,该应用专注于用户登录注册以及文件管理功能。这个DEMO是一个办公自动化系统的简化版本...
这是一个关于基于Web的问卷调查系统的源码包,主要采用了Java技术栈进行开发,结合了SSM(Spring、SpringMVC、MyBatis)和SSH(Struts2、Spring、Hibernate)两大主流框架。这个系统可能适用于高校毕业生的课程设计...
struts2漏洞、Spring远程代码执行漏洞、Java反序列化漏洞 6、建站程序漏洞(1天) Discuz漏洞、CMS漏洞等 三、Web安全系列之防御 1、常见防御方案(1天) 2、安全开发(2天) 开发自检、测试自检、部署自检 开发工具...
与Struts 1和Struts 2等早期流行的框架不同,Stripes采用了更为现代的开发模式和技术,减少了对XML配置的依赖,更多地利用了Java 5中的注解(Annotation)特性来简化配置。 Stripes框架的核心理念是“约定优于配置...