Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP Calling a servlet with parameter using href

 
Danny Baquilod
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello, a have a problem calling a servlet from JSP.. here's my code

I'm calling a servlet name SvPHeader and I'm getting an error HTTP Status 404 - /SvPHeader when clicking "Edit" . Thanks in advance for your assistance

<TR>
<TD><%=rs.getString(1)%></TD>
<TD><%=rs.getString(2)%></TD>
<TD><%=rs.getString(3)%></TD>
<TD><%=rs.getString(4)%></TD>
<td><a href="http://localhost:8081/SvPHeader?pono=<%=rs.getString(2)%>" />Edit</td>

</TR>
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65109
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java code and a result set in a JSP?

In an case, you should be looking at the HTML thtas generated rather than thesaource code.

But, your href is missing the contex path,and why does it have the host part of the URL? Is it in a separate web app?
 
Danny Baquilod
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Java code and a result set in a JSP?

In an case, you should be looking at the HTML thtas generated rather than thesaource code.

But, your href is missing the contex path,and why does it have the host part of the URL? Is it in a separate web app?


Hi, I understand your "shock" reaction. I will change that later on. I'm just starting to move to MVC Thanks for calling my attendtion.

Here is my problem again:
My code is in JSP displaying a table(list of data) and would like to call a servlet and passing a parameter. I tried to google it but I got some answer that I have to include the URL but I'm not sure if I'm getting it right.

In a servlet I would be calling a bean class to set the data and forward to JSP to display it for editing.

Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65109
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the servlet mapping? If you use the <c:url> tag to format the URL using the mapping, it will automatically prepend the context path.

Otherwise, you need to build it up yourself in the format: /context-path/servlet-mapping

To get the context path using the EL: ${pageContext.request.contextPath}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic