Yan's

Information Technology Blog


  • Home

  • Categories

  • Archives

  • Tags

could not initialize proxy - no Session

Posted on 2017-07-07 | In Java |

Error Information:
org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
org.hibernate.LazyInitializationException: could not initialize proxy - no Session


Error Solution:

1
2
3
4
5
6
7
8
9
10
<!-- filter for keeping session not closed until action completes, "no session" problem -->
<!--this filter should be configurated before the filter for "struts2--filter has operation order" -->
<filter>
<filter-name>openSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>openSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

Read more »

Using Struts 2 to upload file

Posted on 2017-07-06 | In Java |

Jsp page

  • method should be “post”
  • configure enctype=”multipart/form-data”
    1
    2
    3
    4
    5
    <FORM id=form1 name=form1
    action="${pageContext.request.contextPath }/linkman_addLinkMan.action"
    method="post" enctype="multipart-form/data">
    <input type="file" name="upload">

Action file

  • define encapsulated variables and their get()&set()

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    // this "upload" should be the same as the "upload" in the jsp file
    private File upload;
    // file name should be (file object variable + "FileName")
    private String uploadFileName;
    public File getUpload() {
    return upload;
    }
    public void setUpload(File upload) {
    this.upload = upload;
    }
    public String getUploadFileName() {
    return uploadFileName;
    }
    public void setUploadFileName(String uploadFileName) {
    this.uploadFileName = uploadFileName;
    }
    Read more »

HHH000142: Bytecode enhancement failed

Posted on 2017-07-05 | In Java |

Error Information:
HHH000142: Bytecode enhancement failed: xxx; nested exception is org.hibernate.HibernateException: HHH000142: Bytecode enhancement failed: xxx
java.lang.ClassCastException: com.github.entity.Customer_$$_javassist_0 cannot be cast to javassist.util.proxy.Proxy


Error Cause:
jar.png


Error Solution:
Delete javassist-3.11.0.GA.jar.

Read more »

HTTP Status 404-No result defined for action xxx and result input

Posted on 2017-07-03 | In Java |

Error Information:
HTTP Status 404 – Not Found
No result defined for action xxx and result input
org.apache.struts2.dispatcher.Dispatcher warn
WARNING: Could not find action or result: xxx


Error Cause:

1
2
3
4
5
6
7
8
9
10
<!--When the form was posted, value="${customer.cid} " would be sent to the "customer.cid"-->
<td colspan="3">
<!--customer.cid is defined as Integer-->
<select name="customer.cid">
<c:forEach var="customer" items="${list }">
<!--here "{customer.cid} " has a wrong blank in the quotation, make value cannot match the variable in the customer-->
<option value="${customer.cid} ">${customer.custName }</option>
</c:forEach>
</select>
</td>

Error Solution: Get rid of the blank in the value of the option label.

Read more »

java.lang.Long cannot be cast to java.lang.Integer

Posted on 2017-07-02 | In Java |

Error Information:
java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer


Error Cause:

1
2
3
4
5
6
7
8
9
10
@SuppressWarnings("unchecked")
public int findCount() {
// here "Customer" is class name
List<Object> list = (List<Object>) this.getHibernateTemplate().find("select count(*) from Customer");
if(list != null && list.size() !=0){
int count = (int) list.get(0); // !!!!!!!error occurs!!!!!!!!!!!
return count;
}
return 0;
}

Read more »

Struts 2 common result types

Posted on 2017-07-01 | In Java |

Dispatcher Result(default set)

Includes or forwards to a view (usually a jsp). Behind the scenes Struts will use a RequestDispatcher, where the target servlet/JSP receives the same request/response objects as the original servlet/JSP. Therefore, you can pass data between them using request.setAttribute() - the Struts action is available.

Shorthand configuration:

1
2
<!-- show list -->
<result name="list">/jsp/customer/list.jsp</result>

Normal configuration:

1
2
3
4
<!-- show list -->
<result name="list" type="dispatcher">
<param name="location">/jsp/customer/list.jsp</param>
</result>

Another parameter:

parse - true by default. If set to false, the location param will not be parsed for Ognl expressions.


Redirect Result

The response is told to redirect the browser to the specified location (a new request from the client). The consequence of doing this means that the action (action instance, action errors, field errors, etc) that was just executed is lost and no longer available. This is because actions are built on a single-thread model. The only way to pass data is through the session or with web parameters (url?name=value) which can be OGNL expressions.

Read more »

Write operations are not allowed in read-only mode (FlushMode.MANUAL)

Posted on 2017-06-29 | In Java |

SSH error information:
HTTP Status 500 – Internal Server Error
Type Exception Report
Message Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove ‘readOnly’ marker from transaction definition.
Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Read more »

Push error in Eclipse, cannot connect, not authorized

Posted on 2017-06-26 | In git |

If set my Two-factor authentication on GitHub, I will encounter this error in Eclipse if still using username + password.

error.png

So there is no choice, go to my GitHub, and then Settings—-Personal access tokens—-Generate new token to get my personal access token, when trying to push again, set items as the figure below:

Read more »

Some ideas about git use in Atom

Posted on 2017-06-26 | In git |

This figure show me the difference between demo(cloned from GitHub) and demo2(created locally and initialized into a repository), the folder .git is hidden by default.

demo-demo2.png
Read more »

Pratical method to insert images into a new post

Posted on 2017-06-26 | In git |

My clean and cute desktop :)
desktop.PNG

So how to insert a picture which you like into a post.


Read more »
123
Yan Zhu

Yan Zhu

Simple & Practical

25 posts
6 categories
23 tags
GitHub
© 2017 - 2018 Yan Zhu
Powered by Hexo
Theme - NexT.Mist