Help ah! Did not engage in a few days to get the java.lang.NullPointerException problem

Category: Web Develop
 
lzlmq
2008-11-20 10:39:56

Sponsored Links
login.jsp code

<? xml version = "1.0" encoding = "utf-8"?>
<! DOCTYPE wml PUBLIC "- / / wapforun / / DTD WML 1.1 / / EN" "
<% @ page contentType = "text / vnd.wap.wml; charset = gb2312" language = "java" import = "java. sql. * "%>
<% response.setContentType (" text / vnd.wap.wml; charset = utf-8 ");%>
<% request.setCharacterEncoding ("utf-8");%>
<wml>
<card id="main" title=" ">
<p align = "center" ;>
username

<input name = "username" type = "text" ; emptyok = "false" value = "" />

password
;
<input name="password" type="password" emptyok="false" value=""/>

<do type = "accept" label = "landing" ;>
<go href="chklogin.jsp" method="post">
<postfield ; name = "username" value = "$ (username)" />
<postfield name = "password" value = "$ (password)" />
</go>
</do>

<a href="reg.jsp"> you have not registered? </A> </p>
</card>
</wml>
------ --------------------------
chklogin.jsp code:

<? xml version = "1.0" encoding = "utf-8"?>
<! DOCTYPE wml PUBLIC "- / / wapforun / / DTD WML 1.1 / / EN" "
<% @ page contentType = "text / vnd.wap.wml; charset = gb2312" language = "java" import = "java.sql. *"%>
<% response.setContentType ("text / vnd.wap.wml; charset = utf-8");%>
<% request. setCharacterEncoding ("utf-8");%>

<jsp: useBean id = "testblog" scope = "page" ; class = "testblog.testblog" />
<%
String username = new String (request.getParameter ("username"). trim (). getBytes ("8859_1"));
String password = new String (request.getParameter ("password"). trim (). getBytes ("8859_1"));
String sql = "select * from user where username = '"+ username +"' and password = '"+ password +"' ";
ResultSet rs = testblog.executeQuery (sql);
if (rs.next ()) {
int id = Integer.parseInt (rs.getString ("id"));
response.sendRedirect ("index.jsp? id =" + id);
rs.close ();
} ;
else
{
rs.close ();
%>
< ; wml>
<card id="main" title=" ">
< p align = "center"> account or password input errors, please re-enter! <anchor> Back <prev/> </anchor>
</p>
</card>
</wml>
<%}%>
---------------------- ---------
chklogin.jsp the error message:

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception
org.apache.jasper.JasperException: Exception in JSP: / chklogin.jsp: 13

10: String password = new ; String (request.getParameter ("password"). trim (). getBytes ("8859_1"));
11: String sql = "select * from user where ; username = '"+ username +"' and password = '"+ password +"' ";
12: ResultSet rs = testblog.executeQuery (sql);
13: if (rs.next ()) {
14: int id = Integer.parseInt (rs.getString ("id"));
15: ; response.sendRedirect ("index.jsp? id =" + id);
16: rs.close ();

Stacktrace:
org.apache . jasper.servlet.JspServletWrapper.handleJspException (JspServletWrapper.java: 504)
org.apache.jasper.servlet.JspServletWrapper.service (JspServletWrapper.java: 393)
org.apache.jasper.servlet.JspServlet . serviceJspFile (JspServlet.java: 314)
org.apache.jasper.servlet.JspServlet.service (JspServlet.java: 264)
javax.servlet.http.HttpServlet.service (HttpServlet.java: 802 )

root cause
java.lang.NullPointerException
org.apache.jsp.chklogin_jsp._jspService (chklogin_jsp.java: 67)
org.apache. jasper.runtime.HttpJspBase.service (HttpJspBase.java: 97)
javax.servlet.http.HttpServlet.service (HttpServlet.java: 802)
org.apache.jasper.servlet.JspServletWrapper.service ( JspServletWrapper.java: 332)
org.apache.jasper.servlet.JspServlet.serviceJspFile (JspServlet.java: 314)
org.apache.jasper.servlet.JspServlet.service (JspServlet.java: 264)
javax.servlet.http.HttpServlet.service (HttpServlet.java: 802)

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.16 logs.

- ------------------------------
testblog which calls the bean code: ;

package testblog;
import java.sql. *;

public ; class testblog
{
String strDBDriver = " sun.jdbc.odbc.JdbcOdbcDriver ";
String strDBUrl =" jdbc: odbc: testblog ";
private Connection conn = null;
private Statement stmt = null;
ResultSet rs = null;
/ / <! - registration database driver ->
; public testblog ()
{
; try
; {
Class.forName (strDBDriver);
}
/ / exception handling
catch (java.lang.ClassNotFoundException e)
{
System.err . println ("testblog ():" + e.getMessage ());
;}
}
; / / <! - establish a database connection and define data query ->
public ResultSet ; executeQuery (String sql)
{
rs = null;
try
{
; conn = DriverManager.getConnection (strDBUrl, "sa", "") ;/ / create a database connection object
stmt = conn. createStatement ();
rs = stmt.executeQuery (sql);
;}
catch (SQLException ex)
{
; System.err.println ("aq.executeQuery:" + ex.getMessage ());
;}
return rs;
}
; / / <! - Definition Data Manipulation ->
public void ; executeUpdate (String sql)
{
stmt = null;
rs = null;
try
{
; conn = DriverManager.getConnection (strDBUrl, "sa", "");
stmt = conn.createStatement ();
stmt.executeQuery (sql);
; stmt.close ();
; conn.close (); ;
}
catch (SQLException ex)
{
; System.err.println ("aq.executeQuery:" + ex.getMessage ()); ;
}
}
/ / <! - close the database connection -> ;
public void closeStmt ()
{
try
; {
stmt.close ();
}
; catch (SQLException e)
; {
e.printStackTrace ();
} ;
}
public void closeConn ()
{
try
{
; conn.close (); ;
}
catch (SQLException e)
{
; e.printStackTrace ();
;}
}
}

Sponsored Links

LAOHOUKZG007
2008-11-20 10:52:45
remember where your values ​​plus TRY, otherwise error
try {
String username = new ; String (request.getParameter ("username"). trim (). getBytes ("8859_1"));
String password = new String (request.getParameter ( "password"). trim (). getBytes ("8859_1"));
String sql = "select * from user where username = '"+ username +"' and password = '"+ password +"' ";
ResultSet ; rs = testblog.executeQuery (sql);
if (rs.next ()) {
int id = Integer.parseInt (rs.getString (" ; id "));
response.sendRedirect (" index.jsp? id = "+ id);
rs.close ();
}
else
{
rs.close ();

} catch (Exception e) {

}
purplelinlin
2008-11-20 11:07:08
in this page chklogin.jsp you get the values ​​from the form judgment.
if (request.getParameter ("username")! = null && request.getParameter ("username"). length ()! = 0)
{
to normal walking The following
try
{

}
catch () {} ...
}

else
{
response.sendRedirect (login page);
}
kaokaokaokaokaocao
2008-11-20 11:27:02
will

String username = new String (request.getParameter ("username"). trim (). getBytes ("8859_1"));

to

String username = new String (request.getParameter ("username"). trim (). getBytes ("8859_1"), "gb2312");
tubufu
2008-11-20 11:38:55
Since suggests:
org.apache . jsp.chklogin_jsp._jspService (chklogin_jsp.java: 67)
would find chklogin_jsp.java the 67th row to see

chklogin_jsp.java should be generated by the application server itself, in the working directory
richard_wz
2008-11-20 11:58:17
Like or not, can be posted chklogin.jsp the entire code
yaoyao0915
2008-11-20 12:01:41
I chklogin.jsp modified to look like this,
<? xml version = "1.0" encoding = "utf-8"?>
<! DOCTYPE wml PUBLIC "- / / wapforun / / DTD WML 1.1 / / EN ""
<% @ page contentType = "text / vnd.wap.wml; charset = gb2312" language = "java" import = "java. sql. * "%>
<% response.setContentType (" text / vnd.wap.wml; charset = utf-8 ");%>
<% ; request.setCharacterEncoding ("utf-8");%>
<jsp: useBean id = "testblog" scope = "page" class = "testblog.testblog" />
<wml>
<card id="main" title=" ">
<%

String username = new String (request.getParameter ("username"));
String password = new String (request.getParameter ("password"));
try {
String sql = "select * from user where username = '" + username + "' and password = '" + password + " ; '";
ResultSet rs = testblog.executeQuery (sql);
if (rs.next ()) {
int id = Integer.parseInt (rs.getString (" ; id "));
response.sendRedirect (" index.jsp? id = "+ id);
rs.close ();
}
else
{
rs.close ();
response.sendRedirect ("err.jsp");}
} catch (Exception e) {out.print ( "Can not get value" + username + password);
}
%>
</card>
</wml>

The results showed that: Failed to get value 111111
111 and 111 which are the username and password you just entered a value, that value can be taken to, but execute sql statement wrong. Where is wrong in the end still can not find, please help look for. .
hfdxq
2008-11-20 12:10:52
JSP programming skills highlights (a problem piece of code)

summary of a practical problem of concentrated essence of a code problem collectibles ; novice combat essential handbook
three fifty yuan to buy the book might as well buy a higher level beginner practical code ; veteran with reference value

a 30 yuan (WORD file electronic documents)

need, please contact: e_mail: fz lotuscn@yahoo.com. cn QQ: 59 5563946 (address, remove spaces)

CONTENTS

1 The selected row is highlighted?
2. drop-down list box to select a value out of a new window?
3. in JSP start execl?
4. two drop-down list box linkage menu ?
5. java how to put a directory of files to another directory specified?
6. production form lines?
7. jsp as a character in discriminating between A and Z?
8. obtain a floating decimal 4, how Write to function interception of two
9. cosmetic transfer character?
10. displays database records, click on the title bar which, in accordance with which heading to sort
11. ; making two buttons
12. use what sql statement of a record in the database, copy the two?
13. controls two buttons with javascript?
14. the jsp database connection
15. in jsp, how to achieve can press ENTER to submit the form?
16. in JSP how to pass an array?
17 pictures taken by address?
18. JSP how to upload images to a database field?
19. automatically refresh the page?
20. automatically submit the form?
21. transfer of data from the JSP to JAVABEAN Lane?
22. weblogic data pool connections? data source JNDI name mysource
23 three drop-down list box linkage menu?
24. in JSP how to call the browser "Save As" function?
25. pages full screen
26, find the number of days between two dates separated: input time format (yyyy-mm-dd)
27. upload file dialog
28. Paging test
29. download file
30. simple character judgment
31. the JSP bean variable or passed to JAVASCRIPT use?
32. put a format (eg yyyy-mm-dd) the date variable into another format (such as dd-mm-yyyy) Date of variables!
33. achieved by adding a line on the page input dialog
34. production Captcha Image?
35. picture Zoom Out Zoom function
36. Click the input box pops up date selection?
37. before uploading the picture you want to view your own uploaded images?
38. arranged in the picture on the page select a picture, and then delete it?
39. ; displays all files in a directory
40. the checkbox selected value is displayed directly in the input text box?
41. Choose a file path directly display the file contents?
42. making progress?
43. characters omitted for longer display?
44 . production calendar?
45. Click on the text pops up a selection box, select the value returned and displayed
46. closed back no frame frame page page?
47 Select the number of records deleted at once?
48. automatically get page file name?
49. invoke the ActiveX control in JSP?
50. use SmartUpload file upload?
51. using iReport and Jasperreport develop reports?
52. Using iText to generate PDF?
53. making picture watermark?
54. in the page shielded keyboard function keys?
55. prohibit users from copying content?
56. realized not in the address bar displays the current URL?
57. Gets the user's real IP address?
58. Gets the user's browser information?
59. Get the current absolute path?
60. the HTML file into an XML file?
61. combining XML and XSL output HTML page?
62. produce dynamic tree menu making?
63. produced similar QQ message alert?
64. jfreechat produced by Zhu, cakes, curve type?
65. text box how allowing only enter numbers?
66. open Word documents and Execl?
67. generate Word and Excel documents?
68. JSP How to read Word content?
69. browse the server directory / file?
70. jsp download box pops up directly download files?
71. configuration data connection pool and data source (Tomcat)?
72. Click on Figure 1 to Figure 2 ?
73. JSP one of the methods shown in the photo?
74. int into Integer way?
75. requests jsp page prohibits caching method?
76. select automatically select one of the values ​​to a text box?
77. JSP database connection?
78. JSP two drop-down list box linkage (database)?
79. JSP character encoding issues and conversion of Guinness?
80. using filter settings request encoding?
81. JSP or Servlet calling DLL?
82. ; the JSP include Applet (clock)?
83. in the Applet displays a html page?
84. enable session Forced fail?
85. iFreme edit box Use?
86. Applet and Servlet communication?
87. JSP form directly into EXCEL?

deitaq
2008-11-20 12:22:39
to ran_ran

the String username = new String (request.getParameter ("username"). trim (). getBytes ("8859_1"));
to String ; username = new String (request.getParameter ("username"). trim (). getBytes ("8859_1"), "gb2312");
post or not ah
sefly001
2008-11-20 12:39:47
I sure did not get a value because, I suggest you use progressive system.out.println () for testing.
wenxys
2008-11-20 12:47:23
finally get the answer is not above said those!
but the database table name is the user,
do not know why, with the user name of the table seems to be doing wrong, I put the table name into userinfo on the line, really depressed death of me!
to thank you for your help!
Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.