Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Prakash N
Problem in Servlet
4 Answer(s)      6 years and 5 months ago
Posted in : Servlet Interview Questions



Advertisement
View Answers

June 4, 2008 at 1:09 PM


please see web.xml file carefully.
there are two tags.
1)servlet
2)servlet-mapping

always remember that in both tags <servlet-name> must be same no matter whatever it is(i.e you can give any name).

and other two subtags are there.
a)<servlet-class> -this must match with the name you have given for your servlet class in your program.
b)<url-pattern> -this must match with name you are using in url.
I hope if you do this you won't have any error.


June 4, 2008 at 7:46 PM


Hi friend,

package javacode;

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class AccessValueServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String title = "Reading All Request Parameters";
out.println(ServletValue.headWithTitle(title) +
"<BODY BGCOLOR=\"pink\">\n" +
"<H1 ALIGN=CENTER>" + title + "</H1>\n" +
"<TABLE BORDER=1 ALIGN=CENTER>\n" +
"<TR BGCOLOR=\"#FFAD00\">\n" +
"<TH>Employee Name<TH>Employee Status(s)");

Enumeration paramNames = request.getParameterNames();
while(paramNames.hasMoreElements()) {
String paramName = (String)paramNames.nextElement();
out.println("<TR><TD>" + paramName + "\n<TD>");
String[] paramValues = request.getParameterValues(paramName);
if (paramValues.length == 1) {
String paramValue = paramValues[0];
if (paramValue.length() == 0)
out.print("<I>No Value</I>");
else
out.print(paramValue);
} else {
out.println("<UL>");
for(int i=0; i<paramValues.length; i++) {
out.println("<LI>" + paramValues[i]);
}
out.println("</UL>");
}
}
out.println("</TABLE>\n</BODY></HTML>");
}

public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
-------------------------------


June 4, 2008 at 7:50 PM


package javacode;

import javax.servlet.*;
import javax.servlet.http.*;

public class ServletValue {
public static final String DOCTYPE =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";

public static String headWithTitle(String title) {
return(DOCTYPE + "\n" +
"<HTML>\n" +
"<HEAD><TITLE>" + title + "</TITLE></HEAD>\n");
}

public static int getIntParameter(HttpServletRequest request,
String paramName,
int defaultValue) {
String paramString = request.getParameter(paramName);
int paramValue;
try {
paramValue = Integer.parseInt(paramString);
} catch(NumberFormatException nfe) { // Handles null and bad format
paramValue = defaultValue;
}
return(paramValue);
}

public static String getCookieValue(Cookie[] cookies,
String cookieName,
String defaultValue) {
for(int i=0; i<cookies.length; i++) {
Cookie cookie = cookies[i];
if (cookieName.equals(cookie.getName()))
return(cookie.getValue());
}
return(defaultValue);
}

}

-------------------------------------


<servlet>
<servlet-name>accessvalue</servlet-name>
<servlet-class>javacode.AccessValueServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>accessvalue</servlet-name>
<url-pattern>/jsp/AccessValueServlet</url-pattern>
</servlet-mapping>



June 4, 2008 at 7:53 PM


This is form code

<html>
<head>
<title>registration form in jsp</title>
</head>
<body>
<table border="1" width="50%" bgcolor="pink">
<tr>
<td width="100%">
<form method="POST" action="/examples/jsp/AccessValueServlet" >

<h2 align="center">Employee registration form</h2>
<table border="1" width="100%">
<tr>
<td width="50%"><b>User Name:</b></td>
<td width="50%"><input type="text" name="username" size="20"/> </td>
</tr>
<tr>
<td width="50%"><b>Last Name:</b></td>
<td width="50%"><input type="text" name="lastname" size="20"/> </td>
</tr>
<tr>
<td width="50%"><b>Email:</b></td>
<td width="50%"><input type="text" name="email" size="20"/> </td>
</tr>
<tr>
<td width="50%"><b>Position:</b></td>
<td width="50%"><input type="text" name="position" size="20"></td>
</tr>
<tr>
<td width="50%"><b>Salary:</b></td>
<td width="50%"><input type="text" name="salary" size="20"></td>
</tr>
</table>
<p><input type="submit" value="Submit" name="submit">
<input type="reset" value="Reset" name="reset"></p>

</form>
</td>
</tr>
</table>
</body>
</html>

----------------------------------------------------------

Read for more details.

http://www.roseindia.net/servlets/


Thanks


Related Tutorials/Questions & Answers:
servlet problem
servlet problem  wheni m deploying an servlet application im getting trouble context [/filename] startup failed due to previous error in tomcat 6.0.
Servlet problem
connectivity code it works but problem is with servlet page. My servlet code...Servlet problem  Hello, I am very shocked about this mysterious problem from last three month and now i hope rose india developers
Advertisements
problem in servlet program
problem in servlet program  Dear Sir, I have a problem to insert the Blob type data like as video file, audio file in the database using Servlet and html code
Servlet Problem - JSP-Servlet
Servlet Problem  Hii I am Ajay . I am makin g a project in java using servlets. I have a database in which I have stored images along with some other info(Name, address type). I want to display that info in text form along
Java Servlet Problem - JSP-Servlet
Java Servlet Problem  I have a servlet class that implemets..., but in the attributeReplaced() method, i want to perform a redirect to another servlet... method. Please help!!  Hi friend, Please explain problem
problem running a servlet on tomcat.
problem running a servlet on tomcat.  i have followed the steps given... to run my servlet that is placed in the directories as it has been mentioned here... be the problem? please help me out
Servlet Problem proceed - JSP-Servlet
Servlet Problem proceed  Thank you fro your reply. But I couldnt find any serious error.Please see this. User is the package classes/User... problem then read more details. http://www.roseindia.net/servlets
Servlet problem - JDBC
Servlet problem  Hii Everyone, I m Ajay. I m making a project using... SQL 2000 database and I have developed a servlet that accepts input from user but however. It gives problem sometimes while at others it works perfectly. I m
logout problem.. - JSP-Servlet
logout problem..  hi... first of all thanks for ur... but their is some problem with the the logout,i m not able to logout when... done in the code i have used session object in project's servlet and jsp
Problem in Servlet - Servlet Interview Questions
Problem in Servlet  Sir, I have pointed everything in web.xml, path class path etc.. empController is my main servlet program and I called in form.... then some exception ..Servlet Exception: empContrller is not a servlet pgm
Jsp ,Servlet Problem - JSP-Servlet
Jsp ,Servlet Problem  hi, m new to jsp n Servlet. i really find ur... with oracle. it worked wonders. now i m starting jsp n servlet learning.. pls... to execute a servlet code on tomcat server... Thanking u... Santosh  
pagination problem - JSP-Servlet
using servlets in that i called a these methods,to call this servlet i created a html file i wrote one form to call this servlet. In this servlet i used doget...(),my problem is that where i have to put & how to do pagination? my code
pagination problem - JSP-Servlet
using servlets in that i called a these methods,to call this servlet i created a html file i wrote one form to call this servlet. In this servlet i used doget...(),my problem is that where i have to put & how to do pagination? my code
problem in programming - JSP-Servlet
problem in programming  Hi! I am new with jsp. I am facing a problem in programming to calculate the time interval between login time and logout time of user
Java Problem - JSP-Servlet
Java Problem  What are the steps to run a java Servlet program.with examples  Hi Friend, Please visit the following link: http://www.roseindia.net/servlets/index.shtml Thanks
servlet problem - Servlet Interview Questions
servlet problem   when i have perform action on submit button then there is no call servlet in my action i have done every effort in this programe... application folder and servlet in classes folder of apache tomcat. The web application
arraylist problem - JSP-Servlet
my code once again only in which i m facing the problem. /* * To change... servlet request * @param response servlet response...); } } this is giving an output in servlet page like: DST_Name: Code TeamLeader
servlet code problem - JSP-Servlet
servlet code problem  This is my JSP code index.jsp Sync... here!!!..., i want to pass the texbox value and file to servlet im stuck with this error plzz help me..., in servlet if i use request.getParameter() its
servlet code problem - JSP-Servlet
servlet code problem  This is my JSP code index.jsp Sync Data Sync Data Please use the following input box to upload file or enter... to servlet im stuck with this error plzz help me..., thanks in advance....  
tomcat problem - JSP-Servlet
perfectly. Kindly let me know what is the problem at an earliest. Thanking... found your problem.. http://www.roseindia.net/web-application-server/tomcat
arraylist problem - JSP-Servlet
and POST methods. * @param request servlet request * @param response servlet response */ /* * To change this template, choose Tools.... It would be good for me to provide you the solution if problem is clear. Thanks
jsp problem - JSP-Servlet
working but my problem is size of image. so can u just help?? code..."); } else{ pw.println("problem in image insertion
jsp problem - JSP-Servlet
working but my problem is size of image. so can u just help?? code..."); } else{ pw.println("problem in image insertion
Servlet compilation problem - Java Beginners
Servlet compilation problem  hi, m a beginner to servlet world... i m facing problem in servlet compilation problem.. i have set the classpath of servlet-api.jar . m using tomcat 6.0 i m unable to compile my servlet program
logout problem?? - JSP-Servlet
logout problem??  sir, the logout code which u have send is not the proper solution coz,by using this code the browser get closed which shuold not happen.to logout properly i think we should empty or clear the browser
JSP Problem - JSP-Servlet
JSP Problem  Hi, I have problem,this is my senario I have one jsp,this jsp having the 3 fields.let me take 3fields userName,emailAddress,phoneNumber and two buttons(AddUser and Submit). Here i want to add 5 Users
resultset problem - JSP-Servlet
resultset problem  hi I have one problem with resultset? ResultSet rs=st.execute("select subjname,staffname from staffdetails"); while(rs.next()) { st.executeUpdate("update CSEFIRSTYEARTIMETABLE set p2
coding problem - JSP-Servlet
coding problem  dear sir i m very new to JSP sir i m getting problem in dynamically changing the option of combobox from database(ms acess) .and after that option being selected for that the record from the databse should
Array problem - JSP-Servlet
.. Bur my problem is that if the pop up window contains only 1 record
servlet program problem - Java Beginners
servlet program problem   i used ur servlet example prg with xml file of helloworld program and i run dat program in tomcat, it shows only... file to run it  Hi Friend, Please clarify your problem. Thanks
Tomcat installation problem - JSP-Servlet
Tomcat installation problem   Hello I have installed Tomcat and my startup and shutdown programs are working but the problem is i couldnt open...:\apache-tomcat-6.0.16; 2) Put the servlet-api.jar into lib folder of apache tomcat
Advertisements
 

 

 

DMCA.com