SSH开发网上商店过程中遇到的16个问题

作者:互联网发布时间:2010-01-07来源:Java中文网 点我投稿

1.字符长度问题

String s=” 容易出现”;

则s.length()的值为4

s.getBytes().length的值为8

2.对象操作

如果对象tmp为null,则无法对其进行tmp.length(),否则出错。

注意进行判空.

如果字符串长度为8,但是截取长度为10,也抛异常.

3.测试Spring+Hibernate:

ApplicationContext ctx=new FileSystemXmlApplicationContext("src/applicationContext.xml");

ProductTypeDAO pdao=(ProductTypeDAO)ctx.getBean("ProductTypeDAO");

4. Spring+Hibernate中applicationContext.xml配置错误,主要由于命名问题:

Error setting property values; nested exception is

org.springframework.beans.NotWritablePropertyException: Invalidproperty 'pTypedao' of bean class[com.Jcuckoo.struts.action.AddPTypeAction]: Bean property 'pTypedao' isnot writable or has an invalid setter method: Does the parameter type ofthe setter match the return type of the getter?

注解:spring默认命名方式不能以双大写字母开头

pTypedao,第一个字母是小写,而第二个字母是大写的属性,它的get和set方法名字不是get+属性第一个字母大写。例如iTestDao的set方法不是setITestDao,可能是setItestDao。所以不建议使用第一个字母是小写,而第二个字母是大写的属性。

另外对应的dao也不能是newsInfodao,我用这个也出现问题,把它改成newInfoDAO解决问题。

5.Struts将控制权限转交到Spring的代码:

struts-config.xml

(1)设置控制转移:

value="org.springframework.web.struts.DelegatingRequestProcessor" />

parameter="com.Jcuckoo.struts.ApplicationResources" />

className="org.springframework.web.struts.ContextLoaderPlugIn">

value="/WEB-INF/classes/applicationContext.xml" />

(2)需要修改

name="loginForm" path="/login" scope="request"

//删除type,控制权交给spring。

type="com.Jcuckoo.struts.action.LoginAction">

(3)修改applicationContext.xml

singleton="false">

6. Struts+Spring+hibernate报错: Hibernate operation: Cannot openconnection; uncategorized SQLException for SQL [???]; SQL state [null];error code [0]; Cannot load JDBC driver class

请在"applicationContext.xml"配置文件中将下面代码

jdbc:jtds:sqlserver://localhost:1433;DatabaseName=test

改成

jdbc:jtds:sqlserver://localhost:1433;DatabaseName=test

千万别笑!格式不同!必须同一行,并且中间不能有空格或其他多余字符!

7.Struct中的Action配置问题

如果直接显示用不到对应的Form,只需要将对应的name属性删掉即可。

刚做了一个程序,从ptype_add.jsp—>addPType.do-->showPType.do-->pTpye_show.jsp显示没有任何问题,但是直接显示showPType.do就不显示,并且控制台不抛异常。原因正如上面分析。

No input attribute for mapping path /SysManager/editPType 并不是说名缺少input属性,而是说,出现错误,无法回跳。

7.下拉选择框

labelProperty="productFactory"/>

其中, products是被显示的集合。Id是Value。productFactory是显示在外面的看的见的信息。

8.文件上传时发生错误:

java.lang.IllegalArgumentException: Cannot invoke com. ProductInfoForm.setFile - argument type mismatch

org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:1778)

org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:1759)

org.apache.commons.beanutils.PropertyUtilsBean.setNestedProperty(PropertyUtilsBean

这个例子是对的 要特别注意的是 form标签里{或是html:form标签里要设置} enctype="multipart/form-data"

因为form 里默认是application/x-www-form-urlencoded,不能用于文件上传;只有使用了multipart/form-data,才能完整的传递文件数据操作!!!

9.Validation.xml的应用:

(1)对应的JSP

validateProductInfoForm(this);">

(2)validation.xml

(3)struts-config.xml

attribute="productInfoForm"

name="productInfoForm"

parameter="method"

path="/SysManager/productInfo"

scope="request"

validate="true"

input="/SysManager/pinfo_add.jsp"

>

(4)对应的ActionForm

public class ProductInfoForm extends ValidatorActionForm{

public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {

// TODO Auto-generated method stub

return super.validate(mapping, request);

}

}

(5)ApplicationResources.properties

errors.productName.required=productName.required

errors.productName.minlength=productName.minlength greater than 6

10.首页重定向:

11.实现两个页面同时刷新:

--------------------------------------------------------------------

onClick="InitRightFrame('editPassword_top.jsp','editPassword.jsp')">密码修改功能

12. 使用bean标签显示时间的格式:

其中的MM要大写!!

13.图片上传:

enctype="multipart/form-data" >

private FormFile file1;

public FormFile getFile1() {

return file1;

}

public void setFile1(FormFile file1) {

this.file1 = file1;

}

public String saveObject(FormFile file){

if (file.getFileName() == null || file.getFileName().equals("")) {

return null;

} else {

String dir = servlet.getServletContext().getRealPath("/newsphoto");

String imageType[] = { "JPG", "jpg", "gif", "bmp", "BMP","pjpeg"};

String fileType = file.getContentType();

int i = fileType.indexOf("/");

fileType = fileType.substring(i + 1);

for (int j = 0; j

if (imageType[j].equals(fileType)) {

String path;

try {

// 调用图片的上传的方法,并且返回上传服务器的路径

path = FileUpLoad.upload(dir, file);

path = "newsphoto/" + path;

return path;

} catch (Exception e) {

e.printStackTrace();

return null;

}

}

}

}

return null;

}

public ActionForward addNewsInfo(ActionMapping mapping, ActionForm form,

HttpServletRequest request, HttpServletResponse response) {

try {

NewInfoForm nf = (NewInfoForm) form;// TODO Auto-generated method stub

NewsInfo news=new NewsInfo();

news.setContent(nf.getContent());

news.setTitle(nf.getTitle());

news.setNewsTime(new Date());

news.setPublishAuthor((String)request.getSession().getAttribute("UserName"));

news.setPicPath1(saveObject(nf.getFile1()));

newInfoDAO.save(news);

return mapping.findForward("AddNewsInfoSuccess");

} catch (RuntimeException e) {

// TODO Auto-generated catch block

e.printStackTrace();

return mapping.findForward("NewsInfoFail");

}

package util;

public class FileUpLoad {

public static String upload(String dir, FormFile formFile) throws Exception {

Date date = new Date();

String fname = formFile.getFileName();

//取文件的后缀

int i = fname.indexOf(".");

String type = fname.substring(i + 1);

//用时间给文件赋新名称

String name = String.valueOf(date.getTime());

fname = name + "." + type;

InputStream streamIn = formFile.getInputStream(); // 创建读取用户上传文件的对象

File uploadFile = new File(dir); // 创建把上传数据写到目标文件的对象

// 判断指定路径是否存在,不存在则创建路径

if (!uploadFile.exists() || uploadFile == null) {

uploadFile.mkdirs();

}

String path = uploadFile.getPath() + "/" + fname;

OutputStream streamOut = new FileOutputStream(path);

int bytesRead = 0;

byte[] buffer = new byte[8192];

while ((bytesRead = streamIn.read(buffer, 0, 8192)) != -1) {

streamOut.write(buffer, 0, bytesRead);

}

streamOut.close();

streamIn.close();

formFile.destroy();

return fname;

}

}

14.字符串分割

String test="好好学习,天天向上,乐观学习";

String []str=test.split(",");

for(int i=0;i

System.out.println(str[i]);

}

15.隔行变色

方法一:struts 奇偶行不同颜色

bgcolor="">

... ...

方法二:

' ...........

16.分栏效果

信息暂时没有!

{

%>


作者:互联网发布时间:2010-01-07来源:Java中文网 点我投稿

1.字符长度问题

String s=” 容易出现”;

则s.length()的值为4

s.getBytes().length的值为8

2.对象操作

如果对象tmp为null,则无法对其进行tmp.length(),否则出错。

注意进行判空.

如果字符串长度为8,但是截取长度为10,也抛异常.

3.测试Spring+Hibernate:

ApplicationContext ctx=new FileSystemXmlApplicationContext("src/applicationContext.xml");

ProductTypeDAO pdao=(ProductTypeDAO)ctx.getBean("ProductTypeDAO");

4. Spring+Hibernate中applicationContext.xml配置错误,主要由于命名问题:

Error setting property values; nested exception is

org.springframework.beans.NotWritablePropertyException: Invalidproperty 'pTypedao' of bean class[com.Jcuckoo.struts.action.AddPTypeAction]: Bean property 'pTypedao' isnot writable or has an invalid setter method: Does the parameter type ofthe setter match the return type of the getter?

注解:spring默认命名方式不能以双大写字母开头

pTypedao,第一个字母是小写,而第二个字母是大写的属性,它的get和set方法名字不是get+属性第一个字母大写。例如iTestDao的set方法不是setITestDao,可能是setItestDao。所以不建议使用第一个字母是小写,而第二个字母是大写的属性。

另外对应的dao也不能是newsInfodao,我用这个也出现问题,把它改成newInfoDAO解决问题。

5.Struts将控制权限转交到Spring的代码:

struts-config.xml

(1)设置控制转移:

value="org.springframework.web.struts.DelegatingRequestProcessor" />

parameter="com.Jcuckoo.struts.ApplicationResources" />

className="org.springframework.web.struts.ContextLoaderPlugIn">

value="/WEB-INF/classes/applicationContext.xml" />

(2)需要修改

name="loginForm" path="/login" scope="request"

//删除type,控制权交给spring。

type="com.Jcuckoo.struts.action.LoginAction">

(3)修改applicationContext.xml

singleton="false">

6. Struts+Spring+hibernate报错: Hibernate operation: Cannot openconnection; uncategorized SQLException for SQL [???]; SQL state [null];error code [0]; Cannot load JDBC driver class

请在"applicationContext.xml"配置文件中将下面代码

jdbc:jtds:sqlserver://localhost:1433;DatabaseName=test

改成

jdbc:jtds:sqlserver://localhost:1433;DatabaseName=test

千万别笑!格式不同!必须同一行,并且中间不能有空格或其他多余字符!

7.Struct中的Action配置问题

如果直接显示用不到对应的Form,只需要将对应的name属性删掉即可。

刚做了一个程序,从ptype_add.jsp—>addPType.do-->showPType.do-->pTpye_show.jsp显示没有任何问题,但是直接显示showPType.do就不显示,并且控制台不抛异常。原因正如上面分析。

No input attribute for mapping path /SysManager/editPType 并不是说名缺少input属性,而是说,出现错误,无法回跳。

7.下拉选择框

labelProperty="productFactory"/>

其中, products是被显示的集合。Id是Value。productFactory是显示在外面的看的见的信息。

8.文件上传时发生错误:

java.lang.IllegalArgumentException: Cannot invoke com. ProductInfoForm.setFile - argument type mismatch

org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:1778)

org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:1759)

org.apache.commons.beanutils.PropertyUtilsBean.setNestedProperty(PropertyUtilsBean

这个例子是对的 要特别注意的是 form标签里{或是html:form标签里要设置} enctype="multipart/form-data"

因为form 里默认是application/x-www-form-urlencoded,不能用于文件上传;只有使用了multipart/form-data,才能完整的传递文件数据操作!!!

9.Validation.xml的应用:

(1)对应的JSP

validateProductInfoForm(this);">

(2)validation.xml

(3)struts-config.xml

attribute="productInfoForm"

name="productInfoForm"

parameter="method"

path="/SysManager/productInfo"

scope="request"

validate="true"

input="/SysManager/pinfo_add.jsp"

>

(4)对应的ActionForm

public class ProductInfoForm extends ValidatorActionForm{

public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {

// TODO Auto-generated method stub

return super.validate(mapping, request);

}

}

(5)ApplicationResources.properties

errors.productName.required=productName.required

errors.productName.minlength=productName.minlength greater than 6

10.首页重定向:

11.实现两个页面同时刷新:

--------------------------------------------------------------------

onClick="InitRightFrame('editPassword_top.jsp','editPassword.jsp')">密码修改功能

12. 使用bean标签显示时间的格式:

其中的MM要大写!!

13.图片上传:

enctype="multipart/form-data" >

private FormFile file1;

public FormFile getFile1() {

return file1;

}

public void setFile1(FormFile file1) {

this.file1 = file1;

}

public String saveObject(FormFile file){

if (file.getFileName() == null || file.getFileName().equals("")) {

return null;

} else {

String dir = servlet.getServletContext().getRealPath("/newsphoto");

String imageType[] = { "JPG", "jpg", "gif", "bmp", "BMP","pjpeg"};

String fileType = file.getContentType();

int i = fileType.indexOf("/");

fileType = fileType.substring(i + 1);

for (int j = 0; j

if (imageType[j].equals(fileType)) {

String path;

try {

// 调用图片的上传的方法,并且返回上传服务器的路径

path = FileUpLoad.upload(dir, file);

path = "newsphoto/" + path;

return path;

} catch (Exception e) {

e.printStackTrace();

return null;

}

}

}

}

return null;

}

public ActionForward addNewsInfo(ActionMapping mapping, ActionForm form,

HttpServletRequest request, HttpServletResponse response) {

try {

NewInfoForm nf = (NewInfoForm) form;// TODO Auto-generated method stub

NewsInfo news=new NewsInfo();

news.setContent(nf.getContent());

news.setTitle(nf.getTitle());

news.setNewsTime(new Date());

news.setPublishAuthor((String)request.getSession().getAttribute("UserName"));

news.setPicPath1(saveObject(nf.getFile1()));

newInfoDAO.save(news);

return mapping.findForward("AddNewsInfoSuccess");

} catch (RuntimeException e) {

// TODO Auto-generated catch block

e.printStackTrace();

return mapping.findForward("NewsInfoFail");

}

package util;

public class FileUpLoad {

public static String upload(String dir, FormFile formFile) throws Exception {

Date date = new Date();

String fname = formFile.getFileName();

//取文件的后缀

int i = fname.indexOf(".");

String type = fname.substring(i + 1);

//用时间给文件赋新名称

String name = String.valueOf(date.getTime());

fname = name + "." + type;

InputStream streamIn = formFile.getInputStream(); // 创建读取用户上传文件的对象

File uploadFile = new File(dir); // 创建把上传数据写到目标文件的对象

// 判断指定路径是否存在,不存在则创建路径

if (!uploadFile.exists() || uploadFile == null) {

uploadFile.mkdirs();

}

String path = uploadFile.getPath() + "/" + fname;

OutputStream streamOut = new FileOutputStream(path);

int bytesRead = 0;

byte[] buffer = new byte[8192];

while ((bytesRead = streamIn.read(buffer, 0, 8192)) != -1) {

streamOut.write(buffer, 0, bytesRead);

}

streamOut.close();

streamIn.close();

formFile.destroy();

return fname;

}

}

14.字符串分割

String test="好好学习,天天向上,乐观学习";

String []str=test.split(",");

for(int i=0;i

System.out.println(str[i]);

}

15.隔行变色

方法一:struts 奇偶行不同颜色

bgcolor="">

... ...

方法二:

' ...........

16.分栏效果

信息暂时没有!

{

%>



相关文章

  • 毕业设计-基于SSH网上商城的设计与实现
  • 摘要 本文讲述了基于SSH 框架的网上商城购物系统的设计与实现.所谓的网上商城购物系统是通过网站推广互联企业的商品和技术服务,并使客户随时可以了解企业和企业的产品,为客户提供在线服务和订单处理功能. 从长期的战略目标来说,网上商城购物网站不 ...查看


  • javaWeb开发文献综述
  • 毕业设计(论文)文献综述 基于JAVA 的火车售票系统的设计 学生姓名 周誉 学 号 [1**********]5 指导教师 柳斌 何剑锋 职称 副教授 专 业 软件工程 二零一五年六月 摘要: 随着我国人口的增长及社会的飞速发展,窗口售票 ...查看


  • 鲜花销售网站的设计与实现
  • 内蒙古科技大学 本科生毕业设计说明书(毕业论文) 题 目:鲜花销售网站的设计与实现 学生姓名: 学 号: 专 业: 班 级: 指导教师:褚燕华老师 鲜花销售网站的设计与实现 摘 要 随着互联网的快速发展,网上购物已经成为一种时尚.人们可以通 ...查看


  • 在线订餐系统设计
  • 本科毕业论文(设计) 题 目 学 生 指导教师 年 级 专 业 二级学院 在线订餐系统设计 2011级 电子信息工程 信息工程学院 信息工程学院 2015年5月 郑重声明 本人的毕业论文(设计)是在指导教师的指导下独立撰写完成的.如有剽窃. ...查看


  • 网络安全通信协议 1
  • 第八章 安全通信协议 第八章 安全通信协议 目前网络面临着各种威胁,其中包括保密数据的泄 露.数据完整性的破坏.身份伪装和拒绝服务等. 保密数据的泄露.罪犯在公网上窃听保密性数据. 这可能是目前互相通信之间的最大障碍.没有加密,发 送的每个 ...查看


  • 00.应用平台安全技术规范
  • 某集团企业信息安全标准 应用平台安全技术标准 1适用范围 某集团区域 2规范解释权 本规定适用于某A 公司信息安全管理中心和各分公司. 3应用平台安全概述 应用平台指建立在网络系统之上的应用软件服务,如数据库服务器.电子邮件服务器.Web ...查看


  • 小型购物系统需求分析
  • 1. 引言 1.1编写目的 2. 综合描述 2.1产品的技术 2.2产品的功能 2.3开发及运行环境 3. 系统功能需求 3.1系统需求分析 3.2系统流程图 4. 其他功能需求 4.1性能需求 4.2 开放性要求 4.3 安全性要求 5. ...查看


  • 软件工程师2011年度工作总结
  • 软件工程师2011年度工作总结 作为一个软件开发工程师(我也是一名软件开发工程师),所实在的如果每年只做那么一两个项目,年终工作总结写起来也应该得心应手的,我们只需要把本年度该项目的基本情况简历表述一下,自己在项目中的角色以及自己在项目中遇 ...查看


  • 人力资源管理系统软件工程毕业设计论文
  • 摘要 人力资源管理系统是现代企业的核心业务系统之一,人力资源管理的状况和水平对企业的运作和效率至关重要.现代企业人力资源管理的内容非常丰富,可能包含档案管理.合同管理.薪酬管理.招聘管理.绩效管理.系统管理等很多部分.在本次毕业设计中,我们 ...查看


热门内容