×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Super Contributor
    Join Date
    Mar 2003
    Posts
    2,426

    Java servlets or JSP

    Does anybody know if JSP can be used to create WML pages or is it better to use java servlets?

    Posted by MoTouman, toumanm@boat.bt.com
    on June 06, 2000 at 18:27

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Posts
    2,426

    RE: Java servlets or JSP

    Posted by kyyuen, kyyuen@hotmail.com
    on June 07, 2000 at 07:11


    i've tried the followings:
    1.in servlet, i've used the following method
    getServletContext().getRequestDispatcher(url).forward(request,response)
    to forward the output to an url.
    2. in jsp, i've added

    3. i've used tomcat successfully to test the above. (tomcat needs to add wml and wmls as new mimetypes.)

    hope these 2 cents of tips help.

    Don't forget to create wml mime type under your web server and add the following tag into you jsp page : if you use jsp 1.1.

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    1

    Re: Java servlets or JSP

    I have a problem when i pass variables from wml to servlets. I am using Nokia Mobile Broser Simulator. Here is my code


    login.wml

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

    <wml>
    <card id="card1" title=" Semester Grade Enquiry System Login Form">
    <p>
    <big></big>Semester Grade Enquiry System Login Form<br/>
    Notice: Fields with * are required.<br/><br/>

    <b>$(errorMsg)</b><br/>

    * User name:<br/>
    <input name="username"/><br/>
    * Password (min. 5 characters):<br/>
    <input type="password" name="password"/><br/>

    <a href="validateloginform.wmls#validate()">Submit Form Data</a>
    </p>
    </card>
    </wml>


    validateloginform.wmls

    extern function validate()
    {
    var form_username = String.trim(WMLBrowser.getVar("username"));
    var form_password = String.trim(WMLBrowser.getVar("password"));


    if (""==form_username){
    WMLBrowser.setVar("errorMsg", "The User Name field must not be empty.");
    WMLBrowser.refresh();
    return;
    }

    if (""==form_password){
    WMLBrowser.setVar("errorMsg", "The Password field must not be empty.");
    WMLBrowser.refresh();
    return;
    }


    if (String.length(form_password) < 5){
    WMLBrowser.setVar("errorMsg", "The password must contain at least 5 characters since a short password is less secure.");
    WMLBrowser.refresh();
    return;
    }


    submit_form(form_username, form_password);
    }

    function submit_form(form_username, form_password)
    {
    WMLBrowser.setVar("errorMsg", "");

    WMLBrowser.setVar("username", form_username);
    WMLBrowser.setVar("password", form_password);

    WMLBrowser.go("validateloginform_success.wml");
    }

    validateloginform_success.wml

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

    <wml>
    <card id="card1" title="Success">
    <do type="accept" label="enter">
    <go href="/wml/LoginServlet">
    </go>
    </do>
    </card>
    </wml>

    LoginServlet

    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 LoginServlet extends HttpServlet
    {

    public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException

    {
    Connection con = null;
    Statement stmt = null;
    ResultSet rs = null;

    res.setContentType("text/vnd.wap.wml");
    PrintWriter out = res.getWriter();



    String username2=req.getParameter("username");
    String password2=req.getParameter("password");


    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=\"login\">");
    out.println(" <p> Login </p>");



    try {


    Class.forName("oracle.jdbc.driver.OracleDriver");


    con = DriverManager.getConnection("jdbcracle:thin:@rccadv33:1521rcl", "scott", "tiger");


    stmt = con.createStatement();



    rs = stmt.executeQuery("select * from login");

    while(rs.next())
    {

    if (username2.equals(rs.getString("username")) && password2.equals(rs.getString("password")))


    {

    out.println("<p>Login Successful<p>");
    res.sendRedirect("success.wml");


    }
    else
    {
    out.println("<p>Please check the entries!<p>");
    }
    }
    }
    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) { }
    }


    }
    }



    When i run my wml file it says Cannot load http://localhost:8080/LoginServlet(Http 404 Error) Please help me with this problem

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×