[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

New to develop dynamic wml with JSP for my project

Posted on 2003-12-07
19
Medium Priority
?
1,108 Views
Last Modified: 2013-12-27
Hi everybody,
             Please help me with this question, I can't start doing my project.  I wanted to develop JSP pages with WML contents and let them show on wap browser or emulators.  

             Now I wrote some wml pages and it shows fine with wap browser or emulators.  The next step is I wanted to have JSP for database operations.   But I just can't directly call up .jsp pages through wap browsers.  What should I do?  Do I need Tomcat and WAPGateway simulators?  If so , how do I set them up to be compatible for the project?

           I have Tomcat, Mysql, and Nokia's Wap Gateway simulator, and also wap browsers and emulators.  Using Windows XP Professional currently.  

Thank.s.. alot...
0
Comment
Question by:Kaiwap
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 8
19 Comments
 
LVL 15

Expert Comment

by:jimmack
ID: 9891861
>> Do I need Tomcat and WAPGateway simulators?

You need a servlet container like Tomcat.  There are also others available (eg. Resin).

In order to return WAP pages, the JSP pages need to begin with:

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//OPENWAVE.COM//DTD WML 1.3//EN"
                "http://www.openwave.com/dtd/wml13.dtd" >
<%response.setContentType("text/vnd.wap.wml");%>
<wml>

This way, the WAP browser will correctly identify the returned page as WML (instead of the standard JSP result which is HTML).
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9891899
To do the database operations, you just need to add the required code to the JSP in the usual way.  After you've declared the contentType, the only difference between an HTML JSP and a WML JSP is the text that you supply outside of the <% %>.
0
 

Author Comment

by:Kaiwap
ID: 9891930
Thanks alot for answering,  this is a sample page,  the jsp area works in html, but the page still hasn't shown in the wap browser.  Do I need to set anything to Tomcat especially for wap browsers?  I have the wireless companion, Openwave SDK 5.1, and Nokia's Internet toolkit.  
When I compile with nokia's internet toolkit, it saids the sentence

<%response.setContentType("text/vnd.wap.wml");%>

is lacking something...

  Do I just use WAP browsers to open file of .JSP directly. Because for IE browser, I type localhost:8080 for the file directory, then call up the html file.  

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN"
     "http://www.wapforum.org/DTD/wml13.dtd">

<%response.setContentType("text/vnd.wap.wml");%>
<wml>
<card>
<%@ page import="java.sql.*" %>
<%
      Class.forName("com.mysql.jdbc.Driver");
      Connection mycon=DriverManager.getConnection("jdbc:mysql://localhost/tee?user=root&password=");
      Statement stmt = mycon.createStatement();
      
      ResultSet myresult = stmt.executeQuery("SELECT * FROM sample");
      
      if(myresult!=null)
      {
            

            while(myresult.next())
            {
                  out.println(myresult.getString("id"));
                  out.println(myresult.getString("name"));
                  out.println(myresult.getString("age"));
                  
            }
            
            }
      %>
</card>
</wml>
0
Q2 2017 - Latest Malware & Internet Attacks

WatchGuard’s Threat Lab is a group of dedicated threat researchers committed to helping you stay ahead of the bad guys by providing in-depth analysis of the top security threats to your network.  Check out our latest Quarterly Internet Security Report!

 
LVL 15

Expert Comment

by:jimmack
ID: 9891944
No, you shouldn't need to do anything special with Tomcat.  It should already be configured to respond with the correct MIME types and so on...

>> is lacking something...

Can you be more specific?  What is the error that was reported?

You just need to open the .jsp page directly from your WAP browser, Tomcat will take care of the response from there.

If you're not sure whether Tomcat is returning WML or not, try opening the page in IE.  You should be able to save the result to a file and check the contents.  Note that it shouldn't open the page in IE because IE shouldn't understand the WML content type.  If IE displays the page, the contentType has not been set correctly.
0
 

Author Comment

by:Kaiwap
ID: 9892043
In IE, it prompts to save target for the file, so it shouldn't be wrong..

This is what was reported in Nokia's Mobile Internet toolkit

Error: Line 4:XML: the name must start with 'Letter' or'_' or'.'
Error: Line 4:XML: root element name does not match with dTD
Error: Line 4:XML: '=' expected
Error: Line 4:XML:'>' expected
Error: Line 7:XML: the name must start with 'Letter' or'_' or '.'
Error: Line 7:XML: not declared element
Error: Line 7:XML: '=' expected
Error: Line 8:XML: the name must start with 'Letter' or'_' or '.'
Error: Line 8:XML: not declared element
Error: Line 9:XML: '=' expected
Error: Line 4:XML: '>' expected
Error: Line 10: XML: entity reference is not terminated with semicolon
Error: Line 10: XML: not declared general entity
Error: Line 29: XML: name with end tag does not match with start tag
Error: Line 61: XML: pending content

I used this as the DTD:
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN"
     "http://www.wapforum.org/DTD/wml13.dtd">

instead of

<!DOCTYPE wml PUBLIC "-//OPENWAVE.COM//DTD WML 1.3//EN"
                "http://www.openwave.com/dtd/wml13.dtd" >

because it saids
can't find DTD "_//OpenWave.com wml 1.3//En". Register DTD first with DTD Manager

Is there a difference???
0
 

Author Comment

by:Kaiwap
ID: 9892108
Hi again,  
      while I was figuring out things, I went to one of the accepted answer on
http://www.experts-exchange.com/Programming/Wireless_Programming/WAP/Q_20802664.html#9838975 

And I tried the 2 samples, and it worked.  So I think my browser and tomcat is working fine now.  The only thing is that the sample first load the test.wml page.  Then link it to the testparam.jsp page.  It worked.  

But for mine, its first page is .jsp already.  Do I need to call the .jsp through the wml page first? I did with a very simple try.  I made a first page to link to the jsp page
<do type="accept"> <go href="query.jsp"/></do>  
but it seems like it is not the reason for that , coz it still doesn't work.  

JSP should be same in both html and WML as you said right?
Here is the html jsp that worked:

query.jsp
<html>
<body><%@ page import="java.sql.*" %>
<%
      Class.forName("com.mysql.jdbc.Driver");
      Connection mycon=DriverManager.getConnection("jdbc:mysql://localhost/tee?user=root&password=");
      Statement stmt = mycon.createStatement();
      
      ResultSet myresult = stmt.executeQuery("SELECT * FROM sample");
      
      if(myresult!=null)
      {
            

            while(myresult.next())
            {
                  out.println(myresult.getString("id"));
                  out.println(myresult.getString("name"));
                  out.println(myresult.getString("age"));
                  //out.println("<td>"+myresult.getString("email")+"</td></tr>");
            }
            
            }
      %>
      </body>
      

thanks alot for sparing your time

0
 
LVL 15

Accepted Solution

by:
jimmack earned 400 total points
ID: 9892178
>>But for mine, its first page is .jsp already.  Do I need to call the .jsp through the wml page first?

No, you can open a JSP page directly from the WAP browser.

(For all the example URL's in this comment, I'm assuming you have a directory called myDbApp).

You could do this with the sample code from the other question.  Instead of going to "http://localhost:8080/myDbApp/test.wml", simply go to "http://localhost:8080/myDbApp/testParam.jsp?name=Hello&mobile=12345"


>> JSP should be same in both html and WML as you said right?

I'm not sure if you understood what I meant (or maybe my explanation was just bad ;-))

A JSP can be used to create either HTML or WML, but you need to use the setContentType to let the browser know what is actually being received.  So you can't do both in one JSP (well... you can, but it's more complicated).

Here is what I think your query.jsp file should contain (I haven't tested the following code, so I apologise if there are some problems):

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//OPENWAVE.COM//DTD WML 1.3//EN"
                "http://www.openwave.com/dtd/wml13.dtd" >
<%@ page import="java.sql.*" %>
<%response.setContentType("text/vnd.wap.wml");%>
<wml>
  <card id="card1" title="DB Results">
<%
     Class.forName("com.mysql.jdbc.Driver");
     Connection mycon=DriverManager.getConnection("jdbc:mysql://localhost/tee?user=root&password=");
     Statement stmt = mycon.createStatement();
     
     ResultSet myresult = stmt.executeQuery("SELECT * FROM sample");
     
     if(myresult!=null)
     {
          while(myresult.next())
          {
               out.print("<p>");
               out.println(myresult.getString("id"));
               out.println(myresult.getString("name"));
               out.println(myresult.getString("age"));
               out.println("</p>");
          }
      }
%>
  </card>
</wml>

To access this page, you'll need to open "http://localhost:8080/myDbApp/query.jsp".

If you still have problems, could you please post the complete JSP file and the complete error/exception report that you get.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9892752
;-)
0
 

Author Comment

by:Kaiwap
ID: 9892801
Gee thanx alot for your help,  I am new to these stuff and often I miss many things.  Now I can have a point to start doing.  Is it neccessary to have
<p> </p>  for displaying?  Because I tried without this tag and it doesn't show the page.  

Your code works just fine, really thx alot. I graded A for this coz it really helps me so much.  I don't really have a point to start doing until now.

Now I will be working to call up data from database and soon will associate the jsp with EJBs.  So mostly for the JSP I just need to add the tag which calls up EJBs, if it works fine with html, it should also works with WML.  

Another thing if you could help me, could you include a code for downloading file?  For example I will keep the file url in the database.  And when I call up the link, it will download the file.  Or should I keep the actual file in the database.  Which one would u suggest.

Your explanation is cool,  I am new to it, so my understanding might be a bit poor.  You are great!!
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9893360
The WAP browser on my Nokia seems quite fussy about the <p></p> tags.  With my experience of Nokia handsets (particularly with J2ME), this is probably because they have implemented the browser properly ;-)

I've done plently of Servlets/JSP, but I haven't used EJBs.

As far as the storage of files in your database is concerned, this depends on what is the best solution for you.  It depends on what you are storing and whether the files can be efficiently (and reliably) fetched using URLs to the targets.  If there are questions over efficiency and reliability, then store them locally in your database to make your system work better.
0
 

Author Comment

by:Kaiwap
ID: 9908282
Thanx alot for all the recommendations,
   now i am trying to this, sending the value to the next page and use it in the sql command as follow:
    notice in the second file, i called up the id from the previous page and try to use it in the sql command
         ResultSet myresult = stmt.executeQuery("SELECT * FROM file where fid="+id+"");
But I wasn't able to get the data out of the database.  Is it because the id was in String? If then how do I change it to int? because the type for "fid" in the database is INT.  Thanks you so much once again if you could help me.


Rall.jsp
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//OPENWAVE.COM//DTD WML 1.3//EN"
                "http://www.openwave.com/dtd/wml13.dtd" >
<%@ page import="java.sql.*" %>
<%response.setContentType("text/vnd.wap.wml");%>
<wml>
  <card id="card1" title="DB Results">
<%

       int id;
     Class.forName("com.mysql.jdbc.Driver");
     Connection mycon=DriverManager.getConnection("jdbc:mysql://localhost/lightweight?user=root&password=");
     Statement stmt = mycon.createStatement();
     
     ResultSet myresult = stmt.executeQuery("SELECT * FROM file where cid=1 ");
     
     if(myresult!=null)
     {
          while(myresult.next())
          {
                out.println("<p>");
      
                        out.println("<a href='confirm.jsp?id="+myresult.getInt("fid")+"&amp; fname="+myresult.getString("file_name")+"'>" + myresult.getString("file_name") + "</a>");
                        
               
                out.println("</p>");
          }
      }
%>
  </card>
</wml>



confirm.jsp

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//OPENWAVE.COM//DTD WML 1.3//EN"
                "http://www.openwave.com/dtd/wml13.dtd" >
<%@ page import="java.sql.*" %>
<%response.setContentType("text/vnd.wap.wml");%>
<wml>
  <card id="card1" title="DB Results">
<%
      Class.forName("com.mysql.jdbc.Driver");
     Connection mycon=DriverManager.getConnection("jdbc:mysql://localhost/lightweight?user=root&password=");
     Statement stmt = mycon.createStatement();
     
      String id = request.getParameter("id");
      ResultSet myresult = stmt.executeQuery("SELECT * FROM file where fid="+id+"");

           
            

      out.println("<p>");
      
      
      out.println("Download:");
      out.println(myresult.getString("file_name"));
      out.println(id);
      
      out.println("<a href=''>confirm</a>");
      out.println("<a href='Rall.jsp'>Back</a>");
      out.println("</p>");

      %>

      
  </card>
</wml>
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9908350
Really this should be asked as another question.  What you're asking could take quite a bit of work.

However, I'm prepared to give you some suggestions here since you seem to be quite new to EE ;-)

If I read your question correctly, then in the first page, the following line works correctly (ie. the HREF in the WAP browser is correct):

                    out.println("<a href='confirm.jsp?id="+myresult.getInt("fid")+"&amp; fname="+myresult.getString("file_name")+"'>" + myresult.getString("file_name") + "</a>");

(I wouldn't recommend the space between "&amp;" and "fname")

Requesting the fid from the table as a string shouldn't be a problem.

Are you getting any errors/exceptions, or does the page actually open in the WAP browser.  If it does, exactly what is displayed?

(You don't need the extra +"" on the end of the query)
0
 

Author Comment

by:Kaiwap
ID: 9908550
Thanks very much for answering, I know it should be asked as another question but since i will be having a couple of question which are related , including the one i asked in another question.  Really thankx and appreciate your generosity.

There are 2 case:  
I tried to open the page with Wireless Companion, nothing is displayed. Only URL not found, I think it is just a phrase pop up when there is error or something in the page.

I also tried to open the pages with Winwap, the page is displayed, but the value I required from the database doesn't show

So I didn't know where the problem is, I check in the database and the attribute names,they are correct.  

If i just simply take out the 2 lines

ResultSet myresult = stmt.executeQuery("SELECT * FROM file where fid="+id"");
            
out.println(myresult.getString("file_name"));

then everything works, but it wasn't what I needed...
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9908578
Hang on ;-)

You're not doing a next() on your ResultSet.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9908581
It may be worth doing a test to ensure that a result has been returned:

if (myresult.next())
{
    // Result has been returned OK
}
else
{
    // No data in result set.
}
0
 

Author Comment

by:Kaiwap
ID: 9910064
I tried to add the line in your comment, still it didn't work.

 But only when I change

ResultSet myresult = stmt.executeQuery("SELECT * FROM file WHERE fid=1235");

fid to be a specific number, then the result is shown.  Plus it works only under Wireless Companion, it doesn't show the value in Winwap.   Why?
                  It still didn't work with the "+id" even though the id is recieved on the page already.  

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//OPENWAVE.COM//DTD WML 1.3//EN"
                "http://www.openwave.com/dtd/wml13.dtd" >
<%@ page import="java.sql.*" %>
<%response.setContentType("text/vnd.wap.wml");%>
<wml>
  <card id="card1" title="DB Results">
<%
      Class.forName("com.mysql.jdbc.Driver");
     Connection mycon=DriverManager.getConnection("jdbc:mysql://localhost/lightweight?user=root&password=");
     Statement stmt = mycon.createStatement();
     
      String id = request.getParameter("id");
      

           ResultSet myresult = stmt.executeQuery("SELECT * FROM file WHERE fid=1235");
            


          if(myresult.next())
          {

      out.println("<p>");
            
      out.println(myresult.getString("file_name"));
      
      out.println("Download:");
      
      out.println(id);
      
      out.println("<a href=''>confirm</a>");
      out.println("<a href='Rall.jsp'>Back</a>");
      out.println("</p>");
           }
      
else
{
}

      %>

      
  </card>
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9911001
When you include the +id, you don't need any extra inverted commas (") after it.  I may help the readability if you put spaces around the + signs.  The line should be:

ResultSet myresult = stmt.executeQuery("SELECT * FROM file where fid=" + id);

Certainly with 1 extra ", it would have been generating a 500 - Internal server error.
0
 

Author Comment

by:Kaiwap
ID: 9948394
Thank you so much for your help, it worked well now.  And sorry for didn't reply for a few  days, I was away on the weekend.  Once again, thanks for all your help and support.  It is really stressful when I just can't get the basic things going.  
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9948421
:-)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using in-flight Wi-Fi when you travel? Business travelers beware! In-flight Wi-Fi networks could rip the door right off your digital privacy portal. That’s no joke either, as it might also provide a convenient entrance for bad threat actors.
This program is used to assist in finding and resolving common problems with wireless connections.
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…

656 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