java开发中碰到的问题记录

布满荆棘的人生 2022-06-06 00:16 431阅读 0赞

积累的问题多了,就不怕问题来。

一,Eclipse配置问题

1.启动项目,内存溢出

Eclipse->Window->Preferences->Server->RuntimeEnvironments->选中Apache Tomcat v5.0->点击Edit按钮->在弹出对话框里点击JRE后面的InstalledJREs按钮->在弹出对话框中选中tomcat使用的那个JRE->点击Edit按钮->在弹出对话框中,找到DefaultVM Arguments,并在输入框中输入:-Xms512M-Xmx1024M -XX:MaxPermSize=512m,然后finish->OK->OK。

2.java文件,实心J变成了空心J

http://blog.sina.com.cn/s/blog\_a7d7993f0102wcp3.html

3.修改了JDK后,启动tomcat报错,提示:

The archive: C:/Program Files(x86)/Java/jdk1.7.0_10/lib/tools.jar which is referenced by the classpath, doesnot exist.

计算机生成了可选文字:国p「o匕lemoccu「red心)'StartinaTomcatv7.0Serveratlocalhost,has~encounteredaproblem·Thearchive<img src=/ProgramFiles(x86)IJavaljdkl.7.0--10llibltoolsjarwhich15referencedbytheclasspath,doesnotexist.">

打开Eclipse中tomcat配置,就是双击server选项卡中的tomcat,然后选择openlaunch configuration,如下图所示:

计算机生成了可选文字:日overviewGeneralInformationSpecifythehostname卜Pandothercommonsettings.TomCatv7.0Se四erat!OCalhOSt卜下lSe四ername:日OStname:localhost,pM0陌旧旧旧丛迎血吐止迅鱼匹四回止一ApacheTomcatv7·0三Con6gurationpath:/serve「s二omcatv7.oserverat.oca.卜IB「owse日,ServerLocationsSPecifytheserverPoth(i.e.cotolino.bose)。nddeployPath.ServerrnustbePublishedwithnomodulespresenttomakechanges.UseworkSPacemetadata(doesnotmodifyTomcatinstallation)‘国use丁omcatinstallation(takescontrolof丁omcatinstallation)UsecustomIocation(doesnotmodifyTomcatinstallation)卜~

打开以后会出现如下界面:

20130519154403903

如上图所示,我标注出了错误路径,将这个错误路径删除,并保证正确配置tools.jar和bootstrap.jar这两个jar包的路径。

二,开发问题

1.struts2:

配置多个拦截器,before正常执行所有拦截器,after只执行最后一个拦截器,待解决。

2.ibatis连接数据库mysql

报错内容: Connection is read-only. Queries leading to data modification are not allowed

  1. (连接是只读的。查询导致数据修改不允许)

问题原因,在spring中没有配置事务的权限:

[html] view plain copy

  1. <**bean** id=”baseTransactionProxy”
  2. class=”org.springframework.transaction.interceptor.TransactionProxyFactoryBean”
  3. abstract=”true”>
  4. <**property name=”transactionManager” ref=”transactionManager” />**
  5. <**property name=”transactionAttributes”>**
  6. <**props**>
  7. <**prop key=”insertSynchronized*“>PROPAGATION_REQUIRES_NEW</prop>**
  8. <**prop key=”insert*“>PROPAGATION_REQUIRED</prop>**
  9. <**prop key=”create*“>PROPAGATION_REQUIRED</prop>**
  10. <**prop key=”add*“>PROPAGATION_REQUIRED</prop>**
  11. <**prop key=”update*“>PROPAGATION_REQUIRED</prop>**
  12. <**prop key=”reset*“>PROPAGATION_REQUIRED</prop>**
  13. <**prop key=”delete*“>PROPAGATION_REQUIRED</prop>**
  14. <**prop key=”del*“>PROPAGATION_REQUIRED</prop>**
  15. <**prop key=”save*“>PROPAGATION_REQUIRED</prop>**
  16. <**prop key=”edit*“>PROPAGATION_REQUIRED</prop>**
  17. <**prop key=”release*“>PROPAGATION_REQUIRED</prop>**
  18. <**prop key=”modify*“>PROPAGATION_REQUIRED</prop>**
  19. <**prop key=”change*“>PROPAGATION_REQUIRED</prop>**
  20. <**prop key=”invoke*“>PROPAGATION_REQUIRED</prop>**
  21. <**prop key=”submit*“>PROPAGATION_REQUIRED</prop>**
  22. <**prop key=”batchImport*“>PROPAGATION_REQUIRED</prop>**
  23. <**prop key=”flush*“>PROPAGATION_REQUIRED</prop>**
  24. <**prop key=”excute*“>PROPAGATION_REQUIRED</prop>**
  25. <**prop key=”replace*“>PROPAGATION_REQUIRED</prop>**
  26. <**prop key=”export*“>PROPAGATION_REQUIRED</prop>**
  27. <**prop key=”*“>PROPAGATION_REQUIRED,readOnly</prop>**
  28. </**props**>
  29. </**property**>
  30. </**bean**>

2.spring 配置

在application.xml中添加

[html] view plain copy

  1. <**context:component-scan base-package=”com.core.mvc” />**

报错:The prefix “context” for element “context:component-scan” is not bound.

里面的内容从

[html] view plain copy

  1. <**beans** xmlns=”http://www.springframework.org/schema/beans“
  2. xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance“ xmlns:aop=”http://www.springframework.org/schema/aop“
  3. xmlns:tx=”http://www.springframework.org/schema/tx“
  4. xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
  5. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
  6. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd“
  7. default-autowire=”byName” default-lazy-init=”true”>

改为

[html] view plain copy

  1. <**beans** xmlns=”http://www.springframework.org/schema/beans“
  2. xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance“ xmlns:context=”http://www.springframework.org/schema/context“
  3. xmlns:aop=”http://www.springframework.org/schema/aop“
  4. xsi:schemaLocation=”http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
  6. http://www.springframework.org/schema/context
  7. http://www.springframework.org/schema/context/spring-context-2.5.xsd
  8. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"**>**

OK!

3.springmvc

3.1 springmvc 传参

controller

[java] view plain copy

  1. @Controller
  2. @RequestMapping(“/test”)
  3. public class MyController {
  4. @Resource
  5. MyService myService;
  6. @RequestMapping(“/lzz”)
  7. public String test(HttpServletRequest request,
  8. HttpServletResponse response, User user) {
  9. System.out.println(user.getUsername());
  10. myService.login(user.getUsername());
  11. return “test”;
  12. }

user对象:

[java] view plain copy

  1. package com.core.mvc.model;
  2. public class User {
  3. private int age;
  4. private String username;
  5. private String password;
  6. public int getAge() {
  7. return age;
  8. }
  9. public void setAge(int age) {
  10. this.age = age;
  11. }
  12. public String getUsername() {
  13. return username;
  14. }
  15. public void setUsername(String username) {
  16. this.username = username;
  17. }
  18. public String getPassword() {
  19. return password;
  20. }
  21. public void setPassword(String password) {
  22. this.password = password;
  23. }
  24. }

jsp:

[html] view plain copy

  1. <**form action=”<%=path%>/test/lzz”>**
  2. <**input type=”text” name=”user.username”>**
  3. <**input type=”text” name=”user.password”>**
  4. <**input type=”submit” value=”test_lzz”>**
  5. </**form**>

jsp使用以上写法,后台不能获取参数改为:

[html] view plain copy

  1. <**form action=”<%=path%>/test/lzz”>**
  2. <**input type=”text” name=”username”>**
  3. <**input type=”text” name=”password”>**
  4. <**input type=”submit” value=”test_lzz”>**
  5. </**form**>

能在后台获取参数!!!

这里必须用name=”test”而不是user.name=”test”,因为默认情况下springMVC是不支持user.name这种传参方式的。

参考地址:http://blog.csdn.net/subuser/article/details/19919121

mysql连接出错,提示:java.sql.SQLException: Unknown system variable ‘language’

原因:mysql的驱动版本过高,修改:

mysql-connector-java-5.1.36.jar 版本太高了,换成

mysql-connector-java-5.1.24.jar 问题解决!

转载网址:http://blog.csdn.net/lipp555/article/details/50518846

java开发遇到的问题总结(一)

0、搭建框架(SSI)时注意事项:

1)写好jsp、Action、bean、dao、service里所用的类后,需要在src/struts-config中配置struts2



2)在WebRoot/spring-config/名.xml中配置spring:

  1. <bean id="Dao类名"
  2. class="Dao的实现类全路径" >
  3. <property name="sqlMapClient">
  4. <ref bean="sqlMapClient" />
  5. </property>
  6. </bean>
  7. <bean id="service类名" class="service的实现类全路径" >
  8. <property name="Dao类名里的属性名(为防止意外可以与下一行的ref bean里填写的一样)">
  9. <ref bean="Dao类名(与上面配置Dao的id名必须一致)" />
  10. </property>
  11. </bean>
  12. <bean id="Action的类名"
  13. class="Action的全路径" singleton="false">
  14. <property name="service里的属性名(为防止意外可以与下一行的ref bean里填写的一样)">
  15. <ref bean="service类名(与上面配置service的id名必须一致)" />
  16. </property>
  17. </bean>

3)配置sqlMapConfig.xml:把你在bean中所写的.xml文件配置到此文件中,如

需要写全路径

4)注意在.xml文件中需要有完整的头部,否则会报错,完整头部:

<?xml version=”1.0” encoding=”UTF-8”?>

<!DOCTYPE sqlMap

PUBLIC “-//ibatis.apache.org//DTD SQL Map 2.0//EN”

“http://ibatis.apache.org/dtd/sql-map-2.dtd">







5)在DaoImpl类中需要继承SqlMapClientDaoSupport因为在spring的Dao时里面依赖注入了它的属性sqlMapClient。

6)注意在sericeImpl类中要写Dao的setter与getter方法,Action类中也要写service与Bean的setter和getter方法。

项目运行流程:Action——>service——>serviceImpl——>Dao——>DaoImpl——>bean中的.xml所对应的sql。

1、报错:Thereis no statement named emergencyKPIspace.codename in this SqlMap.

原因:自己写的.xml没有加载到sqlMapConfig.xml中,应写:

即:绝对路径/你所写的.xml

2、注意:在ibatis中#变量#,是用来传值,$变量名$用来字符串拼接

3、报错:Cannotmake a static reference to the non-static method queryNatureCodeName() from thetype KpiTotalEveNatureDaoInterf

翻译:不能让一个静态引用非静态方法queryNatureCodeNameKpiTotalEveNatureDaoInterf()的类型

原代码:

wKioL1Ybc\_rAe3C8AAG3P3khOIQ440.jpg

原因:return时应该为Dao的对象即小写的kpiTotalEveNatureDaoInterf

4、报错:Themethod getSqlMapClient() is undefined for the type KpiTotalEveNatureDaoImpl

原因:Dao层需要继承extendsSqlMapClientDaoSupport

6、报错:wKiom1YbdFrARNpJAACYamQCTv4117.jpg

原因:框架搭建错误,或者.xml的sql空间名称冲突

7、报错:Exceptionoccurred during processing request: null

java.lang.reflect.InvocationTargetException

  1. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  2. atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  3. atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  4. at java.lang.reflect.Method.invoke(Method.java:597)

原因:查看dao中所引用的sql及命名空间是否正确,或者是xml中sql的id等是否匹配正确。

8、报错:com.ibatis.common.jdbc.exception.NestedSQLException:

-— The erroroccurred while applying a parameter map.

-— Check theemergencyKPIspace3.getQueryEveList-InlineParameterMap.

-— Check the statement(query failed).

-— Cause: java.sql.SQLException: ORA-00933: SQL 命令未正确结束

原因:在JAVA中接接字符串处对应不一致。

9、报错:-—Theerror occurred while applying a parameter map.

-— Check theemergencyKPIspace3.getQueryEveList-InlineParameterMap.

-— Check thestatement (query failed).

-— Cause: java.sql.SQLException: ORA-00904:”B”.”FLD_MAT_HAPPEN_DATE”: 标识符无效

原因:传入时间在.xml拼接的位置不对应,原SQL中的时间条件在哪写,拼接的

<![CDATA[ b.fld_mat_happen_date>=to_date(#fromTime#,’yyyy-MM-dd hh24:mi:ss’)]]>也要写在相应位置上,不能随便放置。

10、当ibatis的SQL中有汉字时需要通过变量来传递。

1)变量不参与业务逻辑时可以直接在DaoImpl中写,如:

wKioL1YbdLKQdiQ4AAGasPng0Hk040.jpg

然后在ibatis的xml文件中用到汉字的地方用#括起来,如select* from 表名 where 字段名=#fault#

2)当其参与业务逻辑时需要在serviceImpl中写

11、ibatis中条件in中传入的字符串会自动在其前加有空格(原因:?),导致匹配不正确,所以在要去掉其空格。例:

for (int i = 0; i < loadcodename.length; i++) {

if(i==(loadcodename.length-1)){

resultString=resultString+”nvl(sum(decode(A.fld_mat_kind,’”+loadcodename[i].trim()+“‘,nvl(taskcount,0),0 )),0)\“colum”+i+”\“”;

}else{

resultString=resultString+”nvl(sum(decode( A.fld_mat_kind,’”+loadcodename[i].trim()+“‘,nvl(taskcount,0),0 )),0) \“colum”+i+”\“,”;

  1. \}
  2. \}

12、报错:Unableto instantiate Action, KpiPerMonSysAction, defined for ‘queryPerMonSysList’ in namespace ‘/‘KpiPerMonSysAction

翻译:KpiPerMonSysAction无法实例化操作,为“queryPerMonSysList”名称空间定义KpiPerMonSysAction“/”

原因:在配置struts的文档中action的class里的内容必须与spring配置文档中的action的id值一致。如

wKiom1YbdNagV425AAFFv4lP9Lo105.jpg

13、报错:-— Theerror occurred while applying a parameter map.

-— Check theemergencyKPIspace10.getQuerySysList-InlineParameterMap.

-— Check thestatement (query failed).

-— Cause: java.sql.SQLException: ORA-01840: 输入值对于日期格式不够长

原因:sql中的日期格式不符合规定的格式

14、报错:Exceptionoccurred during processing request: null

原因:请求或传值时不匹配或传空值。

15、给页面添加“加载中…”代码:

document.getElementById(“wholeEveNatureDataPanel”).innerHTML =””;

Ext.get(“wholeEveNatureDataPanel”).mask(“加载中…”,”x-mask-loading”);

在 Ext.Ajax.request里再添加:Ext.get(“wholeEveNatureDataPanel”).unmask();其中括号里为你自己显示页面的Data要渲染到的地方

16、async:false修改为同步(ajax)

17、给导出的单元格加格式(括起来的为加背景色,两行代码才能设置成功。让其在坛坛坛坛循环单元格时调用)

wKiom1YbdRPyv5YPAAL\_9MEej2M058.jpg

循环单元格时调用以上方法:

wKiom1YbdTyDHbWvAAK7Nlhk3ts461.jpg

wKiom1YbdV6zvVjxAALjMmjvdto561.jpg

转载网址:http://haoxiaoli.blog.51cto.com/8691383/1702179

以下问题是近期工作中遇到的问题,可能大神还有别的解决方式,望指教!

1.在使用goole的GSON将javaBean转成json的时候如果遇到一对多或者多对一的时候会出现循环引用问题,之前没怎么用过GSON所以对其不是很了解,最后果断放弃了使用GSON,换成alibaba的fastjson,是用fastjson之后发现预期效果比GSON的强一些,虽然也会有循环引用的问题,不过发现只是在子类数据和父类数据相同的情况下会出现这种问题,(及多对一的情况下)最后在jsp添加判断果断决绝这个问题。

2.在使用jqueryForm提交带文件的表单时,发现action总是会取到前一个上传的文件,这个问题让我抓耳挠腮,jqueryform提交时设置cache: false 也不行最后想到会不是action没销毁,两次公用一个action造成的,结果在网上找到一篇文章解决了我的问题,文中提到:“ scope=”prototype” 会在该类型的对象被请求时创建一个新的action对象。如果没有配置scope=prototype则添加的时候不会新建一个action,他任然会保留上次访问的过记录的信息。

Code-xml代码 收藏代码

  1. “personAction” scope=“prototype” class=“quickstart.action.PersonAction”>
  2. “personService” />

链接:http://blog.csdn.net/m13666368773/article/details/7440027

3.使用jqueryform提交表单时因为浏览器差异也纯在不少的问题,公司测试使用的浏览器是IE7,代码在firfox下能够正常提交而在IE7上面就不好用,虽然现在很少人用IE7,不过毕竟是个问题,最后针对浏览器的不同提供了两种提交方式

先判断浏览器

Java代码 收藏代码

  1. //判断浏览器
  2. function getExplorer() {
  3. var explorer = window.navigator.userAgent ;
  4. //ie
  5. if (explorer.indexOf(“MSIE”) >= 0) {
  6. return “ie”;
  7. }
  8. //firefox
  9. else if (explorer.indexOf(“Firefox”) >= 0) {
  10. return “Firefox”;
  11. }
  12. //Chrome
  13. else if(explorer.indexOf(“Chrome”) >= 0){
  14. return “Chrome”;
  15. }
  16. //Opera
  17. else if(explorer.indexOf(“Opera”) >= 0){
  18. return “Opera”;
  19. }
  20. //Safari
  21. else if(explorer.indexOf(“Safari”) >= 0){
  22. return “Safari”;
  23. }
  24. }

IE提交方式:

Java代码 收藏代码

  1. //IE或其他浏览器的提交方式
  2. var vision=getExplorer();
  3. if(vision===”Chrome” || vision===”ie” || vision===”Opera” || vision===”Safari”) {
  4. var options = {
  5. url:’<%=basePath%>businessApply_addNonBussinessApply.action’,
  6. type:’POST’,
  7. cache: false,
  8. success:function(msg){
  9. var json=eval(“(“+msg+”)”)
  10. if(json==’larger’){
  11. alert(“上传文件太大,单个文件只限于1M以下.”)
  12. return;
  13. }else if(json==’typerr’){
  14. alert(“文件类型出错”)
  15. return;
  16. }else if(json==’suc’){
  17. alert(“xxx新增成功!”);
  18. $(“#townshipId”).val(“”);
  19. $(“#placeName”).val(“”);
  20. $(“#userkindId”).val(“”);
  21. $(“#applyStatusId”).val(“”);
  22. window.location.href=”<%=basePath %>businessApply_goList.html?type=NOTWORK_INFO”;
  23. }
  24. }
  25. };
  26. setTimeOut($(‘#addbusinessApplyForm’).ajaxSubmit(options),0);
  27. return false;
  28. }

    Firfox提交方式:

Java代码 收藏代码

  1. //火狐浏览器提交方式
  2. if(vision===”Firefox”) {
  3. $(“#addbusinessApplyForm”).ajaxSubmit({
  4. cache: false,
  5. success:function(msg){
  6. var json=eval(“(“+msg+”)”)
  7. if(json==’larger’){
  8. alert(“上传文件太大,单个文件只限于1M以下.请重新上传!”)
  9. return;
  10. }else if(json==’typerr’){
  11. alert(“文件类型出错”)
  12. return;
  13. }else if(json==’suc’){
  14. alert(“初次备案新增成功!”);
  15. $(“#townshipId”).val(“”);
  16. $(“#placeName”).val(“”);
  17. $(“#userkindId”).val(“”);
  18. $(“#applyStatusId”).val(“”);
  19. window.location.href=”<%=basePath %>businessApply_goList.html?type=NOTWORK_INFO”;
  20. }
  21. }
  22. })
  23. return false;
  24. }

发表评论

表情:
评论列表 (有 0 条评论,431人围观)

还没有评论,来说两句吧...

相关阅读

    相关 CSS(面试碰到问题

    这12个问题,基本上就是HTML和CSS基础中的重点个难点了,也是必须要弄清楚的基本问题,其中定位的绝对定位和相对定位到底相对什么定位?这个还是容易被忽视的,浮动也是一个大坑,