Solved

problem with wml and jsp

Posted on 2003-11-17
3
914 Views
Last Modified: 2013-12-27
Ok, here is my problem.
First of all I try to browse a jsp page that gives wml from nokia browser and i get the famous "Server 500 error". I would guess that I have sth wrong with the code but the same page runs correctly under the gelon.net emulators. So what is wrong with the Nokia? Doesnt accept .jsp pages?

Second, I try to pass parameters from an index.wml page to a validate.jsp page that will do the validation. The problem is that the values never get to the jsp page correct, when i do an out.println in order to see what i got the value of the parameter is "undefined"! Can anyone help me?

here is the code:

index.wml page

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">

<wml>
<!-- THIS IS THE FIRST CARD IN THE DECK -->
<card id="LoginCard" title="Login">
<p align="center">
WAP Login
</p>
 <p align="left">
      Login ID: &nbsp;
      <input name="telefono" value=""/><br/>
 </p>
 <p align="left">
      Password:
      <input type="password" name="password" value=""/>
 </p>
 <do type="accept" label="SUBMIT">
    <go method="post" href="validate.jsp">
        <postfield name="telefono" value="$(telefono)"/>
        <postfield name="password" value="$(password)"/>
    </go>
</do>
</card>
</wml>

____________________________________________________
the validate.jsp page


<%@ page contentType="text/vnd.wap.wml"%>
<?xml version=\"1.0\"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*" %>

<%
String username= request.getParameter("telefono");
String password = request.getParameter("password");
String pwd="";
String userid = "";
%>
<wml>
<card id="validation" title="Validation">
<%
if(username.equals("")||password.equals(""))
{
%>
<p align="center">
<b>
 The user name or password was not correct
</b>
</p>
<%
}
else
{
out.println(username);   /**here is where I check to see the values and I get the "undefined"
out.println(password);

Class.forName("org.gjt.mm.mysql.Driver");
Connection conn5 = DriverManager.getConnection("jdbc:mysql://......");
PreparedStatement PStmt = conn5.prepareStatement("select password,id from people where telefono= ?");
PStmt.setString(1,username);
ResultSet rs = PStmt.executeQuery();

while (rs.next()) {
pwd = rs.getString(1);
userid = rs.getString(2);
}

if (password.equals(pwd)) {
%>

<jsp:forward page="menu.jsp">
  <jsp:param name="userid" value="<%=userid%>"/>
</jsp:forward>

<%
}else{
%>
<p align="center">
<b>
 The user name or password was not found in database
</b>
</p>
<%
}
}
%>
</card>
</wml>



Another thing, is it possible to do this <jsp:forward> now that I have the wml? If not how can I automatically redirect user to the main page if the validation is correct?
Thanks for your help.
0
Comment
Question by:annasfe
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
jimmack earned 125 total points
Comment Utility
Hi again :-)

I tried your page (cut down to avoid the database access) and found the following:

1) If no parameters (telefono and password) are supplied in the URL, the getParameter(...) returns null.  This leads to a null pointer exception when you try to compare the values using:

if(username.equals("")||password.equals(""))

You should really include tests for null too:

if((username == null) || username.equals("") || (password == null) || (password.equals(""))

This is probably what is causing the 500 error.

I also tried a couple of other changes including putting all the imports onto one line and changing the "<%@ page" method of setting the response content type to using the response.setContentType() method in the main JSP.

However, like you, I can't get my Nokia 6310i to recognise the returned page (I get "No response, try later") :-(

I've had a look around the web and I found a book that deals with the creation of WML pages using ASP and JSP (and servlets), but your code seems to follow this OK.  The first thing is always "Did you set the content type?" and of course, you do.  If I access my test page using my web browser it claims (correctly) that it doesn't recognise "text/vnd.wap.wml" and allows me to save the response.  The response looks perfectly OK to me.

And then...

Following a hunch ...

Aha!!!

I thought I had seen something like this before ;-)

I don't know if this applies to other WAP browsers, but certainly on my Nokia, it is *very* picky about the WML being correctly formed.  Try adding <p> and </p> at either side of the out.println() statements you have in the "else" clause.  I added those and it worked!

Here is the code I used for testing (this works):

<?xml version="1.0" ?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<%@ page import="java.util.*, java.sql.*, java.io.*" %>

<%
response.setContentType("text/vnd.wap.wml");
String username= request.getParameter("tel");
String password = request.getParameter("pas");
String pwd="";
String userid = "";
%>
<wml>
<card id="validation" title="Validation">
<%
if(username.equals("")||password.equals(""))
{
%>
<p align="center">
<b>
 The user name or password was not correct
</b>
</p>
<%
}
else
{
%>
<p><%= username %></p>
<p><%= password %></p>
<%
}
%>
</card>
</wml>

As far as I can see, forwarding should work OK.
0
 

Author Comment

by:annasfe
Comment Utility
First of all thanks a million Jimmack for putting so much time on it :)

I tried adding your changes to my code and at the beggining I though it worked but then...nothing, it worked only if I was putting the correct username and password, all the other cases (wrong username-password or null) I get server error.
Then I copied the code you send me and although I dont see what is so different with mine...... IT WORKS!!! :)  It must be the imports at the beginning or the way you set the response type, I dont know. Anyway I added the database thing in your code and it seems to work perfectly and the jsp:forward too! Just a commned, in your code you didnt add the null checking that you suggested before.

Anyway, thanks again, you are the best ;)
0
 
LVL 15

Expert Comment

by:jimmack
Comment Utility
>>  in your code you didnt add the null checking

I know.  I was thinking about that after I went to bed ;-)  So long as you realised that and found it that's the important thing ;-)
0

Featured Post

Network it in WD Red

There's an industry-leading WD Red drive for every compatible NAS system to help fulfill your data storage needs. With drives up to 8TB, WD Red offers a wide array of solutions for customers looking to build the biggest, best-performing NAS storage solution.  

Join & Write a Comment

With the purchase of CloudCommand by Comcast customers are left in a bind as subscriptions expire and render the AP's disabled. The following will explain how to flash your Ubiquiti AP's with CloudCommand firmware back to Ubiquiti firmware. HOWTO…
Multi-source agreements are important because they set standards that all manufacturers should follow to ensure that devices are compatible with multiple vendors. The multi-source agreement (MSA) is an agreement that establishes how multiple vendors…
This Micro Tutorial will show you how to maximize your wireless card to its maximum capability. This will be demonstrated using Intel(R) Centrino(R) Wireless-N 2230 wireless card on Windows 8 operating system.
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now