• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

error message

 
Greenhorn
Posts: 20
Windows Vista C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i was trying code in servlet (a simple one as i m beginner)but getting error

i can see the form...but after clicking submit button i get following message



type Status report

message /WebApplication1/newhtml

description The requested resource (/WebApplication1/newhtml) is not available.
Apache Tomcat/6.0.26
 
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That means that the action of the form is not the correct URL for the servlet.
 
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Trupti brane wrote:
message /WebApplication1/newhtml

description The requested resource (/WebApplication1/newhtml) is not available.
Apache Tomcat/6.0.26



Please cross check the <url-pattern> in web.xml and the URL you are hitting when you submit.
If you are unable to sort it out post your code here.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and Welcome to JavaRanch
 
Ranch Hand
Posts: 50
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post your code (JSP, Serlvet, web.xml) here. We then do analysis together to solve your problem.
 
Trupti brane
Greenhorn
Posts: 20
Windows Vista C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
newhtml.html

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form action="http://localhost:8080/WebApplication1/newhtml1" method="post">
<table style="height: 173px;width: 242px">
<tr>
<td>Last Name:</td>
<td><input type="text" name="Last_Name" size="15"></td>
</tr>

<tr>
<td>First Name:</td>
<td><input type="text" name="First_Name" size="15"></td>
</tr>
</table>
<input type="submit" name="submit" value="submit" >
</form>
</body>
</html>

newservlet.java

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class NewServlet1 extends HttpServlet {


protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
String Last_Name = request.getParameter("Last_Name");
String First_Name=request.getParameter("First_Name");



out.println("<html>");
out.println("<head>");
out.println("<title>Form 1</title>");
out.println("</head>");
out.println("<body>");
out.println("<table>");
out.println("<th>DETAILS</th>");
out.println("<tr>");
out.println("<td>Last Name:</td>");
out.println("<td>"+Last_Name+"</td>");
out.println("</tr>");
out.println("<tr>");
out.println("<td>First Name:</td>");
out.println("<td>"+First_Name+"</td>");
out.println("</tr>");
out.println("</table>");
out.println("<h1>Servlet NewServlet1 at " + request.getContextPath () + "</h1>");
out.println("</body>");
out.println("</html>");
} finally {
out.close();
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}


protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

public String getServletInfo() {
return "Short description";
}

}
 
Trupti brane
Greenhorn
Posts: 20
Windows Vista C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i m not getting any error while building and running the code...is there any version problem??

i m using IDE netbins 6.9.1

also i tried code with both tomcat and glass fish server

as i m getting error after i click on submit button even i m thinking it is on action command url.

Trupti brane wrote:newhtml.html

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form action="http://localhost:8080/WebApplication1/newhtml1" method="post">
<table style="height: 173px;width: 242px">
<tr>
<td>Last Name:</td>
<td><input type="text" name="Last_Name" size="15"></td>
</tr>

<tr>
<td>First Name:</td>
<td><input type="text" name="First_Name" size="15"></td>
</tr>
</table>
<input type="submit" name="submit" value="submit" >
</form>
</body>
</html>

newservlet.java

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class NewServlet1 extends HttpServlet {


protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
String Last_Name = request.getParameter("Last_Name");
String First_Name=request.getParameter("First_Name");



out.println("<html>");
out.println("<head>");
out.println("<title>Form 1</title>");
out.println("</head>");
out.println("<body>");
out.println("<table>");
out.println("<th>DETAILS</th>");
out.println("<tr>");
out.println("<td>Last Name:</td>");
out.println("<td>"+Last_Name+"</td>");
out.println("</tr>");
out.println("<tr>");
out.println("<td>First Name:</td>");
out.println("<td>"+First_Name+"</td>");
out.println("</tr>");
out.println("</table>");
out.println("<h1>Servlet NewServlet1 at " + request.getContextPath () + "</h1>");
out.println("</body>");
out.println("</html>");
} finally {
out.close();
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}


protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

public String getServletInfo() {
return "Short description";
}

}

 
Nam Ha
Ranch Hand
Posts: 50
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Trupti brane,

Please post your web.xml also.

Did you match the URL with the servlet?

Your form's action points to http://localhost:8080/WebApplication1/newhtml1



If you want the NewServlet1 will get invoked when hitting Submit button, you need to define a mapping in your web.xml. Please post it here.
 
Trupti brane
Greenhorn
Posts: 20
Windows Vista C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Nam Ha can you tell me what is web.xml??? i do not come across such file.
 
Nam Ha
Ranch Hand
Posts: 50
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Trupti brane wrote:@Nam Ha can you tell me what is web.xml??? i do not come across such file.



web.xml is configuration file for your web application. It is located under /WEB-INF folder of your application.


Take a look here
 
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try writing this in your HTML file <form action="NewServlet1" method="post"> and execute your code instead of your <form> tag
 
Trupti brane
Greenhorn
Posts: 20
Windows Vista C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
THANK YOU SO MUCH @Rameshwar Soni getting output as follows


DETAILS
Last Name: rafael
First Name: nadal


that means in form action i have to always give servlet name to which it belongs???
 
Rameshwar Soni
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes you are right
 
I got this tall by not having enough crisco in my diet as a kid. This ad looks like it had plenty of shortening:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic