473,749 Members | 2,350 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Mapping the Servlet request

11 New Member
Dear Sir,
I have two queries.
First question is:
I have a Html page. On which Have two buttons Submit and Issue.
I want when I click on Sumit button request should be go to submit.jsp. and When I click on Issue button then request should be go to Issue.jsp.But When I click on submit button request do to Issue.jsp.
Second Question is How I reterive the input parameter of html page to submit.jsp.
Please review..

My files are:
login.html:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>A simple JSP application</title>
  4. <head>
  5. <body>
  6. <form method="get" action="tmp">
  7. Name<input type="text" name="user">
  8. <br>
  9. Password<input type="password" name="pass">
  10. <input type="Submit" value="Submit">
  11. <input type="Submit" value="Issue">
  12. </form>
  13. </body>
  14. </html>
  15.  
LoginServlet.ja va:
Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. import javax.servlet.*;
  3. import javax.servlet.http.*;
  4. import java.sql.*;
  5. import java.util.*;
  6. public class LoginServlet extends HttpServlet{ 
  7. public void doGet(HttpServletRequest request, HttpServletResponse response)
  8. throws ServletException,IOException{
  9. try
  10. {
  11. response.setContentType("text/html");
  12. PrintWriter out=response.getWriter();
  13. String user=request.getParameter("user");
  14. String pass=request.getParameter("pass");
  15. out.println("Hello: "+user);
  16. out.println("Hello: "+pass);
  17.  
  18. RequestDispatcher dispatcher1 = 
  19. request.getRequestDispatcher("/Issue.jsp");
  20. dispatcher1.forward(request,response);
  21.  
  22. RequestDispatcher dispatcher = 
  23. request.getRequestDispatcher("/submit.jsp");
  24. dispatcher.forward(request,response);
  25. }
  26. catch(Exception e)
  27. {
  28. e.printStackTrace();
  29. }
  30. }
  31. }
web.xml:
Expand|Select|Wrap|Line Numbers
  1. <web-app>
  2.  
  3. <servlet>
  4. <servlet-name>one</servlet-name>
  5. <servlet-class>LoginServlet</servlet-class>
  6. </servlet>
  7. <servlet-mapping>
  8. <servlet-name>one</servlet-name>
  9. <url-pattern>/tmp</url-pattern>
  10. </servlet-mapping>
  11.  
  12. <jsp-file>submit.jsp</jsp-file>
  13. <jsp-file>Issue.jsp</jsp-file>
  14. <url-pattern>*.do</url-pattern>
  15.  
  16. <welcome-file-list>
  17. <welcome-file>Login.html</welcome-file>
  18. </welcome-file-list>
  19.  
  20. </web-app>
Oct 11 '08 #1
3 2292
chaarmann
785 Recognized Expert Contributor
answer 1:
in your HTML-form-tag, the action must be set to point to your webpage and not to "tmp".

answer 2:
by calling
request.getPara meter("user")
Oct 14 '08 #2
vijaykumardahiya
11 New Member
answer 1:
in your HTML-form-tag, the action must be set to point to your webpage and not to "tmp".

answer 2:
by calling
request.getPara meter("user")

Dear Sir,
In Answer 1:
Whether Its only solution is Java-Script.? so that on Html page when I click on Submit button request go to Submit.jsp or when I click on Issue button request go to issue.jsp
Oct 17 '08 #3
JosAH
11,448 Recognized Expert MVP
Dear Sir,
In Answer 1:
Whether Its only solution is Java-Script.? so that on Html page when I click on Submit button request go to Submit.jsp or when I click on Issue button request go to issue.jsp
Why not have one jsp handle both options? e.g.

Expand|Select|Wrap|Line Numbers
  1. <INPUT TYPE=SUBMIT NAME="button" VALUE="submit"> 
  2. <INPUT TYPE=SUBMIT NAME="button" VALUE="issue"> 
  3.  
Your single jsp would receive one parameter "button" with a value "submit" or
"issue". It can make a decision based on that criteria.

kind regards,

Jos
Oct 17 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
5546
by: Frank | last post by:
Hi there, In web.xml, I know it's possible to do path mapping: <path-mapping url-pattern="/aaa/*" real-path="C:\TEMP\"/> So a call to myserver.com/mywebapp/aaa will redirect to c:\temp. Is it possible to do the same but with a URL?
0
2889
by: Dale | last post by:
Is there any way in the web.xml, to define the servlet mappings in such a way that I want to map all urls, EXCEPT for particular patterns. Here is my problem.... I want to ensure that requests for CSS (*.css) or JS (*.js) files don't submit a request to the server most of the time (so the browser just uses its own cached version). Any other url would hit a default filter or servlet, which would then delegate to other appropriate...
1
4261
by: Vasil Slavov | last post by:
I apologize for the long email. I hope somebody will have time to read it and give some suggestions. I am working on a school project written in Python (using mod_python) and I need to upload a file to a java servlet. Here are the high-level instructions given by the servlet authors (the instructions are geared towards my C#/VB competition (and I really want to show them how cool Python is): - Open the file for reading.
3
22145
by: dinesh prasad | last post by:
I'm trying to use a servlet to process a form, then send that data to an SQL server stored procedure. I'm using the WebLogic 8 App. server. I am able to retrieve database information, so I know my application server can talk to the database. I've determined the failure occurs when the the following statement is executed: cstmt.execute(); (due to the failure of println statements placed afterwards). I get the following error after trying to...
1
7000
by: Farce Milverk | last post by:
Hi, Is it possible to have a Servlet on Server A call a Servlet on Server B (both running single instances of an identical webapplication) without using a Proxy setup? For example, if a request comes into Servlet (on server A) I want the servlet on server B to handle the request at address http://serverB/servlet/servletB... The goal is to have Servlet B handle the request fielded by Server A, and
6
4978
by: santhoskumara | last post by:
How to request to servlet from Ajax and also I got the DOM object in the servlet through Business Logic. Now how will i pass the DOM object from serlvet to Clientside. Where in the client Side i am using Ajax. kindly advice me.
14
2417
by: ramadeviirrigireddy | last post by:
Hi All, I have the following code for form and servlet. when the form is submitted the servlet will print the values passed by the form. i'm not getting the servlet o/p when i submit the form.here is my code:(simple code just for testing i did this program) <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title...
7
1770
evilmonkey
by: evilmonkey | last post by:
My assignment was to create a shopping cart servlet, it works locally on tomcat but when I deploy it to the schools server (also tomcat) it fails to refresh the front page and just prints the HTML Code not the page. Any thoughts or a helping hand would be appreciated. import java.io.*; import java.net.*; import java.text.NumberFormat; import java.util.*; import javax.servlet.*; import javax.servlet.http.*;
0
2649
by: krishna81m | last post by:
Could some one please explain why the session is not being maintained when I am doing a forward in a servlet after setting a cookie. I am even unable to set session attributes or parameters and do a forward from a servlet to another servlet via a JSP page, the attributes seize to exist. I still do not understand the concept of session tracking. First page JSP: _______________________________________________ <%@ page...
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9566
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9388
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9333
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8256
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.