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

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

04/06

作者:互联网发布时间: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年4月,是一家专注于高端智能 手机自主研发的移动互联网公司. 小米手机.miui .米聊是小米公司旗下三大核心业务."为 发烧而生" ...
  • 汽车销售网站管理系统毕业论文
    毕 业 设 计 (说 明 书) 题 目:汽车销售网站管理系统的设计与实现 姓 名: 编 号: 平顶山工业职业技术学院 年 月 日 平顶山工业职业技术学院 毕 业 设 计 (论 文) 任 务 书 姓名 ___徐凤芹_____ 专业 __计算机 ...
  • 基于RaspberryPi实现的智能家居
    摘 要 本文以树莓派为载体进行智能家居控制器的设计.在对现在三种市面上的网络电视的比较中引出毕设的主角--树莓派.首先是LINUX 系统常识性的介绍:然后是在ARM/LINUX平台上面开发应用的两种方法:调用系统已有资源.做程序(C 经典法 ...
  • Linux命令nohup和screen命令的区别
    如果想在关闭ssh连接后刚才启动的程序继续运行怎么办,可以使用nohup.但是如果要求第二天来的时候,一开ssh,还能查看到昨天运行的程序的状态,然后继续工作,这时nohup是不行了,需要使用screen来达到这个目的. nohup命令可以 ...
  • 软件工程毕业论文
    目 第一章 第二章录绪论............................................................................................1需求分析........... ...
  • 求职简历-互联网软件开发工程师
    教育背景 2013.09-至今 软件开发大学 计算机软件与理论 离散数学,C语言,数据结构,操作系统,数据库原理,编译原理,软件工程计算机网络,windows/unix编程,图形图像学 2009.09-2013.07 互联派软件开发学院计算 ...
  • 信息技术与信息安全20**年0712最全
    2014年度信息技术与信息安全公需科目(20140712更新) 第一部分单选题: 1.特别适用于实时和多任务的应用领域的计算机是(D). A.巨型机 B.大型机 C.微型机 D.嵌入式计算机 2.负责对计算机系统的资源进行管理的核心是(C) ...
  • ZXR10 T40G交换机安装与配置手册
    中兴ZXR T40G万兆路由交换机 安装手册 中国电信集团系统集成有限责任公司 2008年9月 目录 1. ZXR10 T40G 体系介绍 .................................................. ...
  • 网站建设过程中有可能遇到的问题
    网站建设过程中有可能遇到的问题. 1.什么是域名? 域名通俗的说也叫网站的网址,如allyr.com 或www.allyr.com 是我们重庆炳卓科技的域名(网址)再如qq.com 是腾讯的域名.域名最后是".com " ...