• Post Reply Bookmark Topic Watch Topic
  • New Topic

passing Data to JSP

 
jakob jaworski
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

I need to pass data from an html file into a JSP hier are the 2 files
thats my Html file and i think this should be ok, because when i press submit it submits me to the JSP file and the URL is /test.jsp?text=car if i input car for example


I think her ist the problem i dont get the request.paramter



the output ist only Hallo, i dont get the text1. so where is my problem?
thanks for help
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two things:
  • You should be submitted requests to servlets, not JSPs. JSPs are for creating views, not processing paramters.
  • Putting Java code in a JSP is an obsolete paractice from prior to 2002. Use JSTL and EL instead.


  • Please read this article for info on properly structuring modern Java web apps.
     
    jakob jaworski
    Greenhorn
    Posts: 15
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I know its not up to date but i have to do it as a task, if i could i would do it with a servlet. But i have to do it this way so can you help me?
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 65530
    108
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Why? Is this a school assignment? If so, it's important that you let us know that. Otherwise, we think that you are writing real code and will advise as such.
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 65530
    108
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    And even without servlets you should be using JSTL and EL.
     
    jakob jaworski
    Greenhorn
    Posts: 15
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Yes its a school assignment
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 65530
    108
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    OK, be aware that in the real world, a JSP as a submission target is considered a poor practice.

    The EL expression to get the value of a request parameter named text1 would be: ${param.text1}
     
    jakob jaworski
    Greenhorn
    Posts: 15
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    thank you for you fast help! ist there maybe a example code how to use it? cause i dont know where to add the ${param.text1} and is it param. or should i give it the name of the variable?
     
    jakob jaworski
    Greenhorn
    Posts: 15
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Ok now i did find it out it must be: value="${param.text1}"

    so the thing is i tryed the code ${bean.op1} and all output i get in the jsp is" Hallo:${param.op1} "
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 65530
    108
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    If your web app is improperly configured, the EL may not evaluate.

    If you put ${3+4} into your JSP and it does not display as 7, then your web app is not configured correctly.

    See the JspFaq ("EL not evaluating?") for more info.
     
    jakob jaworski
    Greenhorn
    Posts: 15
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    yes, its an el problem the how to is only to Tomcat 6 im using tomcat 7 is that a problem?
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 65530
    108
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    No.
     
    jakob jaworski
    Greenhorn
    Posts: 15
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    OK new information im now not even sure if it is the EL cause you have to change the settings in the web.xml wich is part of tomcat. i now realizied that im open the file from the workspace not from the server so you think it still could be the EL?
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 65530
    108
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    jakob jaworski wrote:OK new information im now not even sure if it is the EL cause you have to change the settings in the web.xml wich is part of tomcat. i now realizied that im open the file from the workspace not from the server so you think it still could be the EL?


    Incorrect. You don't change Tomcat's web.xml, you change the one in your own web app. You do have one, right? If not, that's likely a large part of the issue.
     
    jakob jaworski
    Greenhorn
    Posts: 15
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    excuse me for the question but where do i find web app?
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 65530
    108
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    What do you mean? Are you not creating a web app?
     
    jakob jaworski
    Greenhorn
    Posts: 15
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    i have the files in my workspace folder and one war file in tomcat its supposed to be a local app. but in there i dont have an web.xml file
     
    jakob jaworski
    Greenhorn
    Posts: 15
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    thank you a lot for your help i found the mistake
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!