因为是跟着视频学习的,有很多用的东西不一样,但是还是慢慢的摸索出来啦!
1.Microsoft JDBC Driver 的下载安装
只要在网上找到资源一步步来就可以了。
2.配置环境变量
我用的是tomcat6.0首先配的是
classpath和path,这些都是在配jdk的时候就配过了,所以就不详细说明了,只要将lib和bin文件加入到相关的路径下就可以了。
另外的一个问题就是可能会出现Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program
一个这样的问题,这是因为现在的jdk版本不会自动的加载这两个东西了,解决办法:
只要在setclasspath中如下设置就可以了
rem ---------------------------------------------------------------------------
rem Set CLASSPATH and Java options
rem
rem $Id: setclasspath.bat 505241 2007-02-09 10:22:58Z jfclere $
rem ---------------------------------------------------------------------------
set JAVA_HOME=D:\Java\jdk1.6.0_11
set JRE_HOME=D:\Java\jre6
rem Make sure prerequisite environment variab ......
方法一、
login.html
<html>
<head>
<title>用户登录</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
</head>
<script language="javascript">
function check(){
if (document.all.userName.value == ""){
alert("对不起,登录帐号不能为空!");
return false;
}
if (document.all.userPWD.value == ""){
&nb ......
我的系统使用acegi登录认证,并且配置用户缓存
<!-- 缓存器,为userCacheBackend提供缓存管理。 -->
<bean id="cacheManager"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" />
<!-- EhCache一般用途如下:Hibernate缓存,DAO缓存,安全性凭证缓存(Acegi),Web缓存,应用持久化和分布式缓存。 -->
<bean id="userCacheBackend"
class="org.springframework.cache.ehcache.EhCacheFactoryBean">
<property name="cacheManager">
<ref local="cacheManager" />
</property>
<property name="cacheName">
<value>userCache</value>
</property>
</bean>
<!-- 用户缓存器,为daoAuthenticationProvider认证器提供缓存管理。 -->
<bean id="userCache"
class="org.springframework.security.providers.dao.cache.EhCacheBasedUserCache">
<property name="cache" ......
Jsp页面在URL中传递参数会出现乱码
解决方法如下:
一、使用更改Tomcat的方法。这个方法简单,但是需要改动的地方是服务器软件级别的,如果稍微变动系统将无法正确转码,移植性不高。
1、来到tomcat目录,找到conf目录下的server.xml问价,打开,找到<Connector>标签,在最后添加URIEncoding=’GBK’,效果如下:
view plaincopy to clipboardprint?
<Connector
port="8080"maxThreads="150"minSpareThreads="25"maxSpareThreads="75"
enableLookups="false"redirectPort="8443"acceptCount="100"
debug="0"connectionTimeout="20000"
disableUploadTimeout="true" URIEncoding=″GBK″/>
<Connectorport="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"enableLookups="false" redirectPort="8443" acceptCount="100"debug="0" connectionTimeout="20000"disableUploadTimeout="true" URIEncoding=″GBK″/>
这种方法对get这个方法测试成功。
2、在每个Jsp页面添加如下代码
view plaincopy to clipboardprint?
<%@pagepageEncoding=”gb2312″ ......
1.最直接最简单的,方式是把文件地址直接放到html页面的一个链接中。这样做的缺点是把文件在服务器上的路径暴露了,并且还无法对文件下载进行其它的控制(如权限)。这个就不写示例了。
2.在服务器端把文件转换成输出流,写入到response,以response把文件带到浏览器,由浏览器来提示用户是否愿意保存文件到本地。(示例如下)
<%
response.setContentType(fileminitype);
response.setHeader("Location",filename);
response.setHeader("Cache-Control", "max-age=" + cacheTime);
//filename应该是编码后的(utf-8)
response.setHeader("Content-Disposition", "attachment; filename=" + filename);
response.setContentLength(filelength);
OutputStream outputStream = response.getOutputStream();
InputStream inputStream = new FileInputStream(filepath);
byte[] buffer = new byte[1024];
int i = -1;
while ((i = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, i);
}
outputStream.flush();
outputStream.close();
inputStream.close();
outputStream ......
第一种:
就是直接给出下载的地址,这种方式很不好,因为会暴露你的地址,带来很多不安全的因素,可以说是千万不要用这种
第二种:
下载页面
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<html>
<head>
<title>download</title>
</head>
<body>
<a href="xia.jsp?filename=新建文档.txt">新建文档.txt</a>
</body>
</html>
然后编写如下页面
<%@ page contentType="text/html;charset=gbk"%>
<%@ page language="java" import="java.io.*,java.net.*" pageEncoding="gbk"%>
<html>
<head>
<title>test</title>
</head>
<body>
<%
response.setContentType("text/html");
javax.servlet.ServletOutputStream ou = response.getOutputStream();
String filepath="uploadfile/";
String filename=new String(request.getParameter("filename").getBytes("ISO8859_1"),"GB2312").toString();
System.out.println("DownloadFile filepath:" + filepath);
System.out.println("DownloadFile ......