Results 1 to 8 of 8
  1. #1
    Mean KaNean is offline Member
    Join Date
    Jun 2011
    Location
    Lancaster, OH
    Posts
    5
    Rep Power
    0

    Default Multiple JSPs controlled by one servlet.

    Hi guys, I'm new but have been coming here reading through the forums for quite a while. I'm fairly new to Java and wanting to learn more. I'm wanting to create 4 JSPs that will be controlled by one servlet. I have an entry page that has 9 text boxes that will allow a user to input information. Once they enter information I want it to be displayed in a verify page so they can make sure they've entered what they need to before submitting. Once they submit I want to insert the values into a database. I have the values that are entered displaying on the verify page. But when the submit button is hit it sees the values as 0 or null. I know I need to post the code and I will in a bit. I'm not at the computer with the code on it right now. Just wanted to get a basic idea, maybe someone has an example of something similar. Thanks.

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    Usually It make in two phases. You check user fiends (input tags in html) to use JavaScript, and don't submit from if user don't fulling fields. Then you check that parameters in Servlet, if there is parameters bad you do redirect on previous page and show user alert message about what he need do.
    Skype: petrarsentev
    http://TrackStudio.com

  3. #3
    Mean KaNean is offline Member
    Join Date
    Jun 2011
    Location
    Lancaster, OH
    Posts
    5
    Rep Power
    0

    Default

    Here's the code I've come up with. There are 3 files. Any help would be greatly appreciated.

    CodeRefEntry.jsp:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>

    <html>
    <head>
    <title>Code Reference Entry Page</title>

    <%@ page import="org.opers.ecs.access.InformationManager" %>
    <%@ page import="org.opers.ecs.model.CodeReferenceRecord" %>
    <%@ page import="org.opers.ecs.model.CodeReferenceFactory" %>
    <%@ page import="org.opers.ecs.model.FormDetailRecord"%>
    <%@ page import="org.opers.ecs.model.FormIface"%>
    <%@ page import="org.opers.ecs.model.NameValuePair" %>
    <%@ page import="org.opers.ecs.util.CommonConstants" %>
    <%@ page import="org.opers.ecs.util.PersProperties"%>

    <jsp:useBean id="codeReferenceRecord" scope="request" class="org.opers.ecs.model.CodeReferenceRecord" />

    <SCRIPT type="text/javaScript">

    function goToHome(){
    window.location = "CodeRefHome.jsp";
    }

    </SCRIPT>


    </head>

    <body>

    <form name="CodeRefEntry" method = "post" action = "/PersECS/CodeRefServlet">
    <INPUT type="hidden" name="<%= CommonConstants.PARAM_PAGE_ID %>" value="<%= CommonConstants.CODE_REF_ENTRY_JSP %>">


    <table>

    <tr>
    <td class= "Label">Please enter the values</td>
    </tr>
    <tr>
    <td class= "Label">Code Ref ID</td>
    <td><input type="text" name="<%= CommonConstants.PARAM_CODE_REF_ID %>"maxlength ="5"></td>
    </tr>
    <tr>
    <td class= "Label">Code XRef ID</td>
    <td><input type="text" name="<%= CommonConstants.PARAM_CODE_XREF_ID %>" maxlength ="5"></td>
    </tr>
    <tr>
    <td class= "Label">Code Group ID</td>
    <td><input type="text" name="<%= CommonConstants.PARAM_CODE_GROUP_ID %>" maxlength ="3"></td>
    </tr>
    <tr>
    <td class= "Label">Data Key Code</td>
    <td><input type="text" name="<%= CommonConstants.PARAM_DATA_KEY_CODE %>" maxlength ="32"></td>
    </tr>
    <tr>
    <td class= "Label">Data Value Text</td>
    <td><input type="text" name="<%= CommonConstants.PARAM_DATA_VALUE_TEXT %>" maxlength ="100"></td>
    </tr>
    <tr>
    <td class= "Label">Long Desc</td>
    <td><input type="text" name="<%= CommonConstants.PARAM_LONG_DESC %>" maxlength ="255"></td>
    </tr>
    <tr>
    <td class= "Label">Is Valid (Y or N)</td>
    <td><input type="text" name="<%= CommonConstants.PARAM_IS_VALID %>" maxlength ="1"></td>
    </tr>
    <tr>
    <td class= "Label">Order Sequence</td>
    <td><input type="text" name="<%= CommonConstants.PARAM_ORDER_SEQUENCE %>" maxlength ="5"></td>
    </tr>
    <tr>
    <td class= "Label">App Name</td>
    <td><input type="text" name="<%= CommonConstants.PARAM_APP_NAME %>" maxlength ="10"></td>
    </tr>
    <tr>
    <td><input type="submit" ></td>
    <td><input type="reset" value="Reset" onclick = "this.form.reset()"></td>
    </tr>
    <tr>
    <td><input type="button" value="Code Ref Home" onclick="goToHome()"></td>
    </tr>

    </table>


    </form>
    </body>
    </html>

    CodeRefVerify.jsp:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>

    <html>
    <head>
    <title>Code Reference Entry Page</title>

    <%@ page import="org.opers.ecs.access.InformationManager" %>
    <%@ page import="org.opers.ecs.model.CodeReferenceRecord" %>
    <%@ page import="org.opers.ecs.model.CodeReferenceFactory" %>
    <%@ page import="org.opers.ecs.model.FormDetailRecord"%>
    <%@ page import="org.opers.ecs.model.FormIface"%>
    <%@ page import="org.opers.ecs.model.NameValuePair" %>
    <%@ page import="org.opers.ecs.util.CommonConstants" %>
    <%@ page import="org.opers.ecs.util.PersProperties"%>

    <jsp:useBean id="codeReferenceRecord" scope="request" class="org.opers.ecs.model.CodeReferenceRecord" />

    <SCRIPT type="text/javaScript">

    function goToHome(){
    window.location = "CodeRefHome.jsp";
    }

    </SCRIPT>
    </head>

    <body>

    <form name="CodeRefVerify" method = "post" action = "/PersECS/CodeRefServlet">
    <INPUT type="hidden" name="<%= CommonConstants.PARAM_PAGE_ID %>" value="<%= CommonConstants.CODE_REF_VERIFY_JSP %>">


    <table>

    <tr>
    <td>Please verify the information:</td>
    </tr>
    <tr>
    <td>Code Ref ID</td>
    <td><input value = <%=request.getParameter(CommonConstants.PARAM_CODE _REF_ID) %>></td>
    </tr>
    <tr>
    <td>Code XRef ID</td>
    <td><input value = <%=request.getParameter(CommonConstants.PARAM_CODE _XREF_ID) %>></td>
    </tr>
    <tr>
    <td>Code Group ID</td>
    <td><input type ="text" value = <%=request.getParameter(CommonConstants.PARAM_CODE _GROUP_ID) %>></td>
    </tr>
    <tr>
    <td>Data Key Code</td>
    <td><input value = <%=request.getParameter(CommonConstants.PARAM_DATA _KEY_CODE) %>></td>
    </tr>
    <tr>
    <td>Data Value Text</td>
    <td><input value = <%=request.getParameter(CommonConstants.PARAM_DATA _VALUE_TEXT) %>></td>
    </tr>
    <tr>
    <td>Long Desc</td>
    <td><input value = <%=request.getParameter(CommonConstants.PARAM_LONG _DESC) %>></td>
    </tr>
    <tr>
    <td>Is Valid (Y or N)</td>
    <td><input value = <%=request.getParameter(CommonConstants.PARAM_IS_V ALID) %>></td>
    </tr>
    <tr>
    <td>Order Sequence</td>
    <td><input value = <%=request.getParameter(CommonConstants.PARAM_ORDE R_SEQUENCE) %>></td>
    </tr>
    <tr>
    <td>App Name</td>
    <td><input value = <%=request.getParameter(CommonConstants.PARAM_APP_ NAME)%>></td>
    </tr>
    <tr>
    <td><input type="submit"></td>
    </tr>
    <tr>
    <td><input type="button" value="Code Ref Home" onclick="goToHome()"></td>
    </tr>

    </table>



    </form>
    </body>
    </html>

    CodeRefServlet.java

    package org.opers.ecs.servlet;

    import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletRequest;

    import org.opers.ecs.model.CodeReferenceRecord;
    import org.opers.ecs.model.MessageIface;
    import org.opers.ecs.model.ReportManager;
    import org.opers.ecs.util.CommonConstants;

    import com.ibm.etools.webservice.wscommonbnd.Parameter;
    import com.ibm.ws.webservices.xml.waswebservices.paramete r;
    import com.ibm.xtq.ast.nodes.ValueOf;

    public class CodeRefServlet extends org.opers.ecs.servlet.BasicServlet {
    /**
    *
    */
    private static final long serialVersionUID = 1L;

    public void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException {

    performTask(request, response);

    }
    /**
    * Process incoming HTTP POST requests
    *
    * @param request Object that encapsulates the request to the servlet
    * @param response Object that encapsulates the response from the servlet
    */
    public void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException {

    performTask(request, response);

    }
    /**
    * Process incoming requests for information
    *
    * @param request Object that encapsulates the request to the servlet
    * @param response Object that encapsulates the response from the servlet
    */

    public void performTask(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) {
    super.performTask(request, response);

    try {
    RequestDispatcher rd = null;

    CodeReferenceRecord cdRequests = new CodeReferenceRecord();

    String comingFrom = request.getParameter(CommonConstants.PARAM_PAGE_ID );

    if(CommonConstants.CODE_REF_ENTRY_JSP.equalsIgnore Case(comingFrom)){

    //String codeRefId = request.getParameter(CommonConstants.PARAM_CODE_RE F_ID);
    //String codeXRefId = request.getParameter(CommonConstants.PARAM_CODE_XR EF_ID);
    String codeGroupId = request.getParameter(CommonConstants.PARAM_CODE_GR OUP_ID);
    String dataKeyCode = request.getParameter(CommonConstants.PARAM_DATA_KE Y_CODE);
    String dataValueText = request.getParameter(CommonConstants.PARAM_DATA_VA LUE_TEXT);
    String longDesc = request.getParameter(CommonConstants.PARAM_LONG_DE SC);
    String isValid = request.getParameter(CommonConstants.PARAM_IS_VALI D);
    //String orderSeq = request.getParameter(CommonConstants.PARAM_ORDER_S EQUENCE);
    String appName = request.getParameter(CommonConstants.PARAM_APP_NAM E);

    // //cdRequests.setCodeRefId(codeRefId);
    // //cdRequests.setCodeXrefId(codeXRefId);
    cdRequests.setCodeGroupId(codeGroupId);
    cdRequests.setDataKeyCode(dataKeyCode);
    cdRequests.setDataValueText(dataValueText);
    cdRequests.setLongDesc(longDesc);
    cdRequests.setIsValid(isValid);
    //cdRequests.setOrderSeq(orderSeq);
    cdRequests.setAppName(appName);

    rd = request.getRequestDispatcher(CommonConstants.JSP_F OLDER + CommonConstants.CODE_REF_VERIFY_JSP);
    rd.forward(request,response);

    }else if (CommonConstants.CODE_REF_VERIFY_JSP.equalsIgnoreC ase(comingFrom)){

    //CodeReferenceRecord cdRequests = new CodeReferenceRecord();

    //String codeRefId = request.getParameter(CommonConstants.PARAM_CODE_RE F_ID);
    //String codeXRefId = request.getParameter(CommonConstants.PARAM_CODE_XR EF_ID);
    // String codeGroupId = request.getParameter(CommonConstants.PARAM_CODE_GR OUP_ID);
    // String dataKeyCode = request.getParameter(CommonConstants.PARAM_DATA_KE Y_CODE);
    // String dataValueText = request.getParameter(CommonConstants.PARAM_DATA_VA LUE_TEXT);
    // String longDesc = request.getParameter(CommonConstants.PARAM_LONG_DE SC);
    // String isValid = request.getParameter(CommonConstants.PARAM_IS_VALI D);
    // //String orderSeq = request.getParameter(CommonConstants.PARAM_ORDER_S EQUENCE);
    // String appName = request.getParameter(CommonConstants.PARAM_APP_NAM E);
    //
    // //cdRequests.setCodeRefId(codeRefId);
    // //cdRequests.setCodeXrefId(codeXRefId);
    // cdRequests.setCodeGroupId(codeGroupId);
    // cdRequests.setDataKeyCode(dataKeyCode);
    // cdRequests.setDataValueText(dataValueText);
    // cdRequests.setLongDesc(longDesc);
    // cdRequests.setIsValid(isValid);
    // //cdRequests.setOrderSeq(orderSeq);
    // cdRequests.setAppName(appName);

    ReportManager.insertReferenceRecord(cdRequests);

    }


    }catch(Throwable theException) {
    this.redirectToMessagePage(request, response, MessageIface.MC_SYSTEM_ERROR);
    return;
    }
    }
    }
    Last edited by Mean KaNean; 06-03-2011 at 07:30 PM.

  4. #4
    Mean KaNean is offline Member
    Join Date
    Jun 2011
    Location
    Lancaster, OH
    Posts
    5
    Rep Power
    0

    Default

    I accedently pasted in the wrong code for the servlet when I first posted this. It's fixed now. Thanks for any help.

  5. #5
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    So Did you solve your task? I guess you have been waiting that anybody would write full code. Just try to find info about validate user data in web. That is all.
    Regard.
    Skype: petrarsentev
    http://TrackStudio.com

  6. #6
    Mean KaNean is offline Member
    Join Date
    Jun 2011
    Location
    Lancaster, OH
    Posts
    5
    Rep Power
    0

    Default

    No I haven't figured it out yet. Are you saying I need to use session?

  7. #7
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    Oh I looked at your code and notice that you didn't give name for inputs tags, Hence when you try to get this data in Sevlet you have null. You need change your code like that
    Java Code:
    <input name=<%=request.getParameter(CommonConstants.PARAM_CODE _REF_ID)%> value=<%=request.getParameter(CommonConstants.PARAM_CODE _REF_ID) %>>
    Because when you submit form browser assigns for there input anonymous name. I hope it help you.
    Skype: petrarsentev
    http://TrackStudio.com

  8. #8
    Mean KaNean is offline Member
    Join Date
    Jun 2011
    Location
    Lancaster, OH
    Posts
    5
    Rep Power
    0

    Default

    I noticed that too after a day of trying to figure out what was wrong with it. Thanks for the help.

Similar Threads

  1. Passing Paramters between jsps through URL
    By maas in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 07-21-2010, 06:07 PM
  2. Replies: 0
    Last Post: 01-22-2008, 04:31 AM
  3. Design Editor For JSPs
    By jazz17782 in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 01-12-2008, 01:52 AM
  4. jsps with html
    By gayatridevi in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 12-31-2007, 01:42 PM
  5. jsps with html
    By gayatridevi in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 12-19-2007, 12:06 PM

Posting Permissions

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