Writing a servlet code
Hi all i am newbie to the servlet programming. I need your help. Actually my problem is, I need to send a message to a remote server. Say i need to send message to the Msn.com by getting a username and password from the user and it will be sent to the MSN.com. how do i go about doing that. can anyone reply me asap.
Thank you
Shree
Hi Shree
If you want to send a message to MSN.com
1.
You have to first find what attribute names that the MSN.com is expecting. There Syntax and case is also important. When it comes to password it could be Password or password or sPassword or any format that they specify.
2.
Then you have to find out what method that the MSN.com use to process the fields that you send. That is there are two ways that it could process POST and GET. If they are using POST you have to set your method as POST or if it's GET set it as GET
eg. <FORM action="msn.com" method=post>
Also note that you have to specify the action in your form where that is the actual place where your fields are going to be processed.
3.
So the last thing you have to do is making the html form with the above collected information
eg.
<FORM action="msn.com" method=post>
User Name<INPUT TYPE=TEXT NAME=USER_NAME>
<BR>
Password <INPUT TYPE=PASSWORD NAME=PASSWORD>
<BR>
<INPUT TYPE=SUBMIT>
</FORM>
Similar Messages
-
Writing to servlet output stream
Hi All,
I am writing to a servlet(imageservlet) output stream in a jsp page two times as follows:
<img src="\imageservlet?key=x1">
<img src="\imageservlet?key=x2">
It is causing memory errors. Do I have to take special precautions?
Thanks inadvance.Hi,
THis is my servlet code.
import java.io.*;
import java.io.StringWriter;
import javax.servlet.http.*;
import javax.servlet.*;
import java.awt.Color;
import com.trizetto.healthweb.service.GenerateImage;
* Simple servlet to use with Image I/O generator
public class GenerateImageServlet extends HttpServlet
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
String className="PieChartGenerator";
if(request.getParameter("keyName").equals("Pie"))
className=PieChartGenerator";
else if( request.getParameter("keyName").equals("Gantt") )
className="GanttChartGenerator";
try
GenerateImage ge=
(GenerateImage) Class.forName(className).newInstance();
String type = ge.createImage(response.getOutputStream());
response.setContentType(type);
catch (Exception e)
throw new ServletException(e);
But this one does not generate image. The image is generated from the Graphics object of the Frame.
Something like the following code:
http://www.javaworld.com/javaworld/jw-05-2000/servlets/Servlets.zip
http://www.javaworld.com/javaworld/jw-05-2000/jw-0505-servlets-p2.html
http://www.javaworld.com/javaworld/jw-05-2000/jw-0505-servlets-p1.html
I am using Java 1.1.
I am running my app. in websphere. The error happens randomly while I am stopping the websphere application server.
Thanks in advance. -
Flush parameter of jsp:include has no effect on servlet code
I am running 9.0.3 and my jsp code looks like:
<jsp:include page =".." flush="false"/>
but the resulting servlet code is:
pageContext.include( __url);
Which defaults to flushing the buffer!
Does anyone know a work around or if Oracle is going to fix this?
Thanks,
MikeTry:
public class ... extends ...
private static final boolean antialias = Boolean.getBoolean ("swing.aatext");
private static Map hintsMap = null;
@SuppressWarnings("unchecked")
static final Map getHints() {
if (hintsMap == null) {
hintsMap = (Map)(Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints")); //NOI18N
if (hintsMap == null) {
hintsMap = new HashMap();
if (antialias) {
hintsMap.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
return hintsMap;
... later in class ...
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.addRenderingHints(getHints());
super.paintComponent(g);
...needed this so custom paint would use AA. In my app I wrote text in my component and it was not AA, this turned it on.
I don't think I had the same problem you, as my jlabels were always aa.
Edited by: 805835 on Oct 27, 2010 5:06 PM
Edited by: 805835 on Oct 27, 2010 5:07 PM -
How to retrieve "env-entry" in servlet code
i have a pretty straight-forward web app, which contains a servlet, among other things. the web app is packaged in .war, and it in turn is part of a .ear file. i am using WAS 640 sneak preview on windows xp.
in the web.xml file, i added the following lines:
<env-entry>
<description>some texts</description>
<env-entry-name>myapp.home</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>c:/myapp</env-entry-value>
</env-entry>
in my servlet code, i try to retrieve the value for "myapp.home" like this:
try
Context ctx = new InitialContext();
home = (String) ctx.lookup("java:comp/env/myapp.home");
} catch (Exception ex) {
ex.printStackTrace();
after .ear is deployed, i can see in the JDNI Registry (using Visual Admin Tool), myapp.home is added to the tree:
webContainer
-applications
--myCompany.com
---myEarFileName
myWebAppRoot
java:comp
env
myapp.home
the entry has the correct class name and object value.
when the servlet code that performs the jndi lookup is called, i get an exception:
com.sap.engine.services.jndi.persistent.exceptions.NameNotFoundException: Path to object does not exist at : java:comp
??? QUESTIONS:
#1 what am i doing wrong?
#2 if the lookup name must contain the entire jndi tree as listed above, then how can this code be portable to other app servers?
thoughts are greatly appreciated.thanks for the hints, but unfortunately they didn't work.
1. after switching the order of value and type in env-entry, rebuild/redeplpoy, same exception. the ordering probably didn't matter since even with the reversed order, the name and value showed up correctly under the jndi tree.
2. well, i tried giving it the full path, starting with 'webContainer', then 'applications' etc, separated by forward slash. now the exception says path to webContainer is not found.
so what gives? are there no standards? -
How to translate this statement to java servlet code
INSERT INTO table_name (column1, column2,...)
VALUES (value1, value2,....)You wouldn't translate that statement to servlet code. The idea doesn't make any sense. However you might include it in a servlet; read the tutorial that zadok linked to.
-
I m new to servlets.
I just copied a servlet code from servlet Help.Then tried to compile with it JDK1.3.But it showing error.It is not compiling package Javax .What may be the possible error.Right, the javax.servlet packages are not part of J2SE.
You'll need a servlet engine to run your servlets/JSPs. It'll have the servlet.jar containing the javax.servlet packages. You'll have to add that to your CLASSPATH when you compile.
I'd recommend Tomcat as your servlet engine. It's capable and free:
http://jakrata.apache.org/tomcat
% -
Help translating a servlet code to bean
hi all
i'd like to translate a servlet code to bean code
the servlet, called from the <img src""> tag in my web page retrieves an images from a database and, setting the response content-type to "image" returns the image.
i'd like to do it through the common getXxx/setXxx methods of a bean
how to do it?
that's the servlet's code:
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
response.setContentType("text/html");
ServletOutputStream out = response.getOutputStream();
try
Connection connection=(Connection)getServletContext().getAttribute("connection");
Statement s=connection.createStatement();
response.setContentType("image/jpeg");
ResultSet rs=s.executeQuery("select "+request.getParameter("col")+" from products where id="+request.getParameter("id"));
while(rs.next())
out.write(rs.getBytes(request.getParameter("col")));
catch(SQLException s)
response.setContentType("text/html");
catch(NullPointerException n)
out.close();
} thanx in advance
sandrotry this:
<%
response.setContentType("text/html");
try {
Connection connection=(Connection)application.getAttribute"connection");
Statement s=connection.createStatement();
response.setContentType("image/jpeg");
ResultSet rs=s.executeQuery("select "+
request.getParameter("col")+
" from products where id="+
request.getParameter("id"));
while(rs.next()) {
%>
<%= rs.getBytes(request.getParameter"col"))) %>
<%
} catch(SQLException s) {
response.setContentType("text/html");
} catch(NullPointerException n) {
%> -
Running a servlet code over Tomcat 4.1
MY HTML CODE THAT CALLS THE SERVLET:
<html>
<body>
<form method="post"action="http://localhost:1234/examples/servlets/program">
Name : <input type=text name="text1">
<input type="submit">
</form>
</body>
</html>
MY SERVLET CODE THAT I HAVE ALREADY SUCCESSFULY EXECUTED ON TOMCAT 3.2.1:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class program extends HttpServlet
public void service(HttpServletRequest
req,HttpServletResponse res)throws
IOException,ServletException
PrintWriter out= res.getWriter();
out.println("Hello World!");
String str= req.getParameter("text1");
out.println("WElcome:"+str);
out.close();
1.==>Any body please tell what all classpaths I have to set here?
2.==>Do I need to write any xml file for running this code ..if yes then please tell what to write in the xml code and where to save it.
3.==>Please tell me where to save my servlet code and html code in Tomcat 4.1
4.==> Do I need any batch file during its execution and lastly how to execute it in Tomcat 4.1...
I have already successfully executed the program in Tomcat 3.2.1
5==> Please check if my codes are OK to run over Tomcat 4.1You should get in the habit of creating war files ( Web Archive file ).
You can deploy a war file to any servlet container like tomcat.
Maven2 is a nice tool that helps you build war files.
Here is an article on how to get started.
http://www.javaworld.com/javaworld/jw-12-2005/jw-1205-maven.html -
Running a servlet code in Tomcat 4.1 or higher
MY HTML CODE THAT CALLS THE SERVLET:
<html>
<body>
<form method="post"action="http://localhost:1234/examples/servlets/program">
Name : <input type=text name="text1"><br><br><br>
<input type="submit">
</form>
</body>
</html>
MY SERVLET CODE THAT I HAVE ALREADY SUCCESSFULY EXECUTED ON TOMCAT 3.2.1:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class program extends HttpServlet
public void service(HttpServletRequest
req,HttpServletResponse res)throws
IOException,ServletException
PrintWriter out= res.getWriter();
out.println("Hello World!");
String str= req.getParameter("text1");
out.println("WElcome:"+str);
out.close();
Please tell me the exact class paths to set or any batch file to be made,where to save the servlet and html codes.Also do i need to write any other to execute the above servlet in tomcat 4.1 or higher i.e any xml file etc and if yes then please let me know the code and where to save it.
Please also verify the method of executing this servlet.http://forum.java.sun.com/thread.jspa?threadID=5237132&tstart=15
-
Closing a browser with the help of servlet code
Is it possible to close a browser by using servlet code?
If so please help me with code.
ThanksThis is really a javascript question, but it's:
window.close() -
How to disable client cookie using Servlet code
Hi All,
I want to disable the client cookie using JSP or servlet code.Is it possible how I can do it.
Thanks in Advance .Hi,
first of all, the URL rewriting option (URLRewritingEnabled) in the weblogic.xml must be set to true.
Now, for all first-timer web requests the BEA WLS always uses URL rewriting in addition to cookies to see wether the browser accepts cookies or not.
I would try to rip of all of the cookies in the header, then flush the response to force the http header to be written.
I have never tried it and has no idea if it will work, however the teory behind supports the idea.
This will not work for toggling session tracking mechanism from a session already established with cookies, the session will be lost if attempted to do this without the URL-rewriting enabled on the page.
- Anders M. -
Sample controler. servlet code wanted
Dear All
Can some one please mail me a sample controler.jsp / Servlet code preferable a professional one with session tracking.
[email protected]
Thanks in AdvanceTry Struts from jakarta.apache.org
It blows out any other controller from the planet
HTH
Trajano Roberto -
Forum wellwishers giv some simple easy to understand Servlet Codes for JServlet beginners an especially me with the code explanation.
Tks
MichelFdO MStart reading part II of the Java EE tutorial: http://java.sun.com/javaee/5/docs/tutorial/doc/bnadp.html
Servlets are covered in chapter 4 and on. -
Sample Servlet code that connects to Microsoft SQL 2008
Does anybody have sample Servlet code that connects to a Microsoft SQL 2008 Resource Pool?
Thank you.JDBC is used to talk to databases. Not database utilities. As an example SSIS is not a database.
So the question would be is the 2008 "Resource Governor" (of which "Resource Pools" are part) a utility or a database entity?
[http://technet.microsoft.com/en-us/library/bb933866.aspx]
I would guess that it isn't a database entity.
Thus the only way to access it is if a database entity allows you do access it. And for that you would need to look for SQL Server system proc(s). -
Nedd to find basic servlet code
Java novice
I need basic servlet code that will capture the input of one form field and write it to a flat file on the server. Servlet will be called in html form action. Any good sources to start with? It appears that this is so basic that I've had trouble finding anything out there.
ThanksIf what you want is to learn the basic stuff invloved in doing what you want to do.
Just follow the java servlet tutorial and io tutorial (You can use google to reach those)
Maybe you are looking for
-
Options for full screen images
Hello! I'm new. So far really like Muse. I'm creating a website where the single image fills the screen. Realizing different people have different resolution screens. How is the best way to create a layout in Muse (widget) Which would allow the image
-
Please help, trying to get SIM to work
Hi, I sure someone can help. I am from Canada and traveling abroad in Germany. My carrier in Canada is Koodo and Ye iPhone comes unlocked. However, every time I put in my German sim card Fonic, it sends me to the activation process and gives me t
-
Dear All, I need to test the load balancing on the RAC, so i need to know how can i know the number of sessions on each instance ? Exp: Suppose i have 15 sessions 8 sessions on instance number 1 7 sessions on instance number 2, what is the query for
-
Help - PDF Fillable Form stopped working
I have a couple of PDF fillable forms (from the IRS and the Commonwealth of Massachusetts) that I have added information to and saved before, but now they won't let me save any changes I make. For the Mass form, I've tried downloading a new one and u
-
OracleParameter.Size Error help me~~~!!!
Error Source --> OracleCommand cmd = new OracleCommand("", con); cmd.CommandTimeout = 120; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandT