2017-11-17 10 views
0

私は春のmvcを使用していますが、コールコントローラなしでjsp page into java pageに値を渡すようになりました。エラーが発生しました。spring mvcを使用してJavaに値JSPページを渡す方法は?

JSPページ

このページでは、私は、Javaコードを使用しますが、別のJavaページ

<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%> 
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> 
<%@page import="com.sample.utility.AutoIncrement" %> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>check page</title> 
</head> 
<body> 

     <div id="login_form"> 
    <form:form action="check" method="post"> 
     <table> 

      <tr>    
      <%String val=AutoIncrement.auto("ShopInfo"); System.out.println(" val : "+val);%>             
       <td class="f1_label">Shop code :</td>     
       <td>     
       <input type="text" name="shopcode" value="<%=val%>" />    

       </td> 
      </tr> 
      <tr> 
       <td class="f1_label">name :</td><td><input type="text" name="name" value="" /> 
       </td> 
      </tr> 
      <tr> 
       <td> 
        <input type="submit" name="login" value="Submit" style="font-size:18px; " /> 
       </td> 
      </tr> 
     </table> 
    </form:form> 
</div> 

</body> 
</html> 

Javaページに値を渡すことができません:このコードは以下の

がここにできないのJavaですjspページの戻り値

public static String auto(String value) 
     { 
      String reVal=""; 
      System.out.println("Inc val : "+value); 
      Session session = sessionFactory.openSession(); 
      try  
      {         
       session.beginTransaction().begin(); 
       String SQL_QUERY = "{CALL pro_autoincrement('"+value+"') }"; 
       query = session.createSQLQuery(SQL_QUERY); 
       reVal=query.toString(); 
       System.out.println("Inc val : "+reVal); 
       session.getTransaction().commit(); 
      } 
      catch(Exception ex) 
      {  
      if (session.getTransaction().getStatus() == TransactionStatus.ACTIVE 
        || session.getTransaction().getStatus() == TransactionStatus.MARKED_ROLLBACK) { 
       session.getTransaction().rollback(); 
      } 
      } 
      finally 
      {   
       session.close(); 
      } 
      return reVal;  
     } 

エラー:

SEVERE: Servlet.service() for servlet [jsp] in context with path [/annotation-based] threw exception [An exception occurred processing JSP page /welcome.jsp at line 18 

15:   <table> 
16:   
17:    <tr>    
18:    <%String val=AutoIncrement.auto("ShopInfo"); System.out.println(" val : "+val);%>             
19:     <td class="f1_label">Shop code :</td>     
20:     <td>     
21:     <input type="text" name="shopcode" value="<%=val%>" />    


Stacktrace:] with root cause 
java.lang.NullPointerException 
    at com.sample.utility.AutoIncrement.auto(AutoIncrement.java:26) 
    at org.apache.jsp.welcome_jsp._jspService(welcome_jsp.java:81) 
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432) 
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) 
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) 

答えて

0

Insted of this。 reVal = query.toString();あなたはこの

レバル=(String)をsession.createQuery(のqueryString).UniqueResult()のように行うことができます

上記のメソッドはオブジェクトを返します。したがって、「キャストを文字列フォーマットに」入力する必要があります。

+0

同じエラーを表示しています!!!! –

関連する問題