Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Using a method within jsp

  • 08-05-2007 3:58pm
    #1
    Registered Users, Registered Users 2 Posts: 1,559 ✭✭✭


    Is there anyway of writing a method within a jsp?

    Do I have to write it within a class and access it from there?

    Can I write a method within a jsp?
    eg. a boolean method.

    Also

    If I wanted 2 submit buttons to appear if only a certain condition is true otherwise only one button how could I go about doing that?


Comments

  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Regarding the last question you may want to have a read of this. The rest is fine.


  • Moderators, Science, Health & Environment Moderators Posts: 10,088 Mod ✭✭✭✭marco_polo


    quinnd6 wrote:
    Is there anyway of writing a method within a jsp?

    Do I have to write it within a class and access it from there?

    Can I write a method within a jsp?
    eg. a boolean method.

    Also

    If I wanted 2 submit buttons to appear if only a certain condition is true otherwise only one button how could I go about doing that?

    You can declare methods, variables etc within declaration tags in JSP <%! .. %>
    <%! 
       int count=0;
    
       int getCount(){
           return ++count;
       }
    %>
    
    You can then call this method in scriptlet tags <% ... %>
    <% out.println("getCount()") %> 
    


  • Registered Users, Registered Users 2 Posts: 1,559 ✭✭✭quinnd6


    Ok I tried this

    <div id="release">
    <input id="submitButton" name="submit" type="submit" value="Release Mail" onclick="this.enabled = false; return true;">
           
    <% if(spamID.indexOf("&cmd=1")!==-1) { %>
    <input id="submitButton2" name="submit" type="submit" value="Release Mail and Whitelist Sender" onclick="this.enabled = false; return true;">
    <% } %>
    </div>

    It just gives me a blank page.


  • Registered Users, Registered Users 2 Posts: 1,127 ✭✭✭smcelhinney


    When is the blank page appearing?

    Before you click? Or after...?

    Can you post the full code? It could be that it hasnt rendered any JSP at all. What does spamID do?

    Use [ CODE ] [/ CODE ] tags too..


  • Moderators, Science, Health & Environment Moderators Posts: 10,088 Mod ✭✭✭✭marco_polo


    I'd say it is probably not compilling, not sure what you are trying to do, you seem to have java code embedded in the HTML tags that is not contained within a scriptlet tag. "onclick" is a javascript function it has nothing to do with JSP.

    onclick="this.enabled = false; return true;

    Could you be a bit more specific about when you want the button to appear or not, ie where is the spam condition set etc? Maybe post the whole JSP so far


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 1,559 ✭✭✭quinnd6


    The rest of the code is ok.
    The first submit button is fine and works ok.
    The jsp uses ajax I think so its okay that it has the javascript code.

    if the string spamId contains &cmd=1 It has to display the second submit button otherwise I dont need the second submit button appearing.

    Thats what I was trying to do.

    The rest of the code is ok.


  • Closed Accounts Posts: 198 ✭✭sh_o


    The condition looks incorrect to me:

    <% if(spamID.indexOf("&cmd=1") !== -1) { %>

    Should probably be:

    <% if(spamID.indexOf("&cmd=1") != -1) { %>


  • Registered Users, Registered Users 2 Posts: 1,559 ✭✭✭quinnd6


    Im after discovering that &cmd=0 isn't part of the spamId at all.

    Its seperated from it by an &.
    How could I extract it if theres an & seperating it rather than a normal space.
    When you use request.getParameter it gets the different strings but assumes they're seperated by a space.

    So any advice?


  • Registered Users, Registered Users 2 Posts: 1,559 ✭✭✭quinnd6


    Does HttpServletRequestWrapper contain a method
    setAttribute(string,string)

    Im kinda unsure.
    It seems to say its inherited at the bottom but I dont know

    http://tomcat.apache.org/tomcat-5.5-doc/servletapi/javax/servlet/http/HttpServletRequestWrapper.html


Advertisement