|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#16
|
|||||||
|
|||||||
|
Quote:
req.getParameter() can return null if any of the parameters do not exist. Check if the names used are correct. Also, I would recommend writing the code a little more robust. Example: java Code:
A proper null reference checking will ensure that you don't get NullPointerException. Quote:
Sorry, no.
__________________
|
|
#17
|
||||||
|
||||||
|
Quote:
I am not getting nullpointerexception for the program but it says cannot load servlet. Is the insert into statements correct?? I am sorry for asking your mail id. I thought i can clarify my doubts. anyway sorry. |
|
#18
|
||||
|
||||
|
Could you print the stack trace from your program and post it here?
|
|
#19
|
|||
|
|||
|
Quote:
This is the stack trace i got in my program Nov 26, 2007 10:32:31 AM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet RegisterServlet threw exception java.lang.NullPointerException at RegisterServlet.doGet(RegisterServlet.java:30) at javax.servlet.http.HttpServlet.service(HttpServlet.java:689) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868) at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProt ocol.java:663) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684) at java.lang.Thread.run(Unknown Source) |
|
#20
|
||||
|
||||
|
Quote:
If the actual line numbers in your code are the same as what you posted, you are getting a NullPointerException around where I thought it would be - I recommend that you modify your code to check for the null reference, as suggested earlier. |
|
#21
|
|||
|
|||
|
import java.io.*;
import java.sql.*; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import javax.servlet.*; import javax.servlet.http.*; public class RegisterServlet extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException { Connection con = null; Statement stmt = null; ResultSet rs = null; PreparedStatement ps = null; res.setContentType("text/vnd.wap.wml"); PrintWriter out = res.getWriter(); out.println("<?xml version=\"1.0\"?>"); out.println("<!DOCTYPE wml PUBLIC " + "\"-//WAPFORUM//DTD WML 1.1//EN\" " + "\"http://www.wapforum.org/DTD/wml_1.1.xml\">"); out.println("<wml>"); out.println("<card id=\"new\" title=\"Register\">"); out.println(" <p> Login </p>"); try { Class.forName("oracle.jdbc.driver.OracleDriver"); con = DriverManager.getConnection("jdbc racle:thin:@rccadv33:1521 rcl", "scott", "tiger");stmt = con.createStatement(); String str = "insert into login values(?,?)"; ps = con.prepareStatement(str); String username3=req.getParameter("name"); String password3=req.getParameter("pswd"); String confirmpassword3=req.getParameter("confirmpswd"); ps.setString(1, username3); ps.setString(2, password3) ; ps.executeUpdate(); res.sendRedirect("registrationsuccess.wml"); // show that the new account has been created out.println(" Hello : "); out.println(" '"+username3+"'"); ps.close(); } catch (IOException e) { // you handle the exception here e.printStackTrace(); } catch(ClassNotFoundException e) { out.println("Couldn't load database driver: " + e.getMessage()); out.println("hi"); } catch(SQLException e) { out.println("SQLException caught is: " + e.getMessage()); out.println("<p>hi</p>"); out.println("</card>"); out.println("</wml>"); } finally { try { if (con != null) con.close(); } catch (SQLException ignored) { } } } } Now i am getting another strange problem, the null values are getting inserted into database. I am passing parameters correctly know? Can you please modify my code so that i can correctly insert the values into database. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > WAP Programming > Wml With Servlets .. Does It Work? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|