473,513 Members | 2,519 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Acces to a servlet...

1 New Member
Hi,

I truly make a lot of atemps, and I decided to ask to you
I have this web
http://www.aduanet.gob.pe/aduanas/in...HRMCFLlega.htm
I have to make a java application to make this form request and save the result page that if you see the source code apears that the form action connect to
Expand|Select|Wrap|Line Numbers
  1. /servlet/CRManFLlega
I ask you if someone knows how to make this connection with a java console application, only to save the result
Thanks a lot and I hope toy can help me
Nov 17 '08 #1
1 1194
Dököll
2,364 Recognized Expert Top Contributor
Greetings!

I saw servlet, and I jumped. I did not go to the site. Can you tell us a little more? Can you add the full code, you might get better luck that way...

Have a look here meanwhile, I could not say too much was understandable but I did get the fact that you need to retrieve something:

Expand|Select|Wrap|Line Numbers
  1.  
  2. //import packages/libraries
  3.  
  4. import java.io.*;
  5. import java.sql.*;
  6. import javax.servlet.*;
  7. import javax.servlet.http.*;
  8.  
  9. //start you request
  10. public class NameOfYourServlet extends HttpServlet{
  11.   public void doGet(HttpServletRequest request, 
  12. HttpServletResponse response) throws 
  13.                               ServletException, IOException{
  14.  
  15. //tell the servlet the type of gui the results will load in, in this case, HTML...
  16.  
  17.     response.setContentType("text/html");
  18.     PrintWriter pw = response.getWriter();
  19.  
  20. //You should have had an ODBC connection ready, 
  21. //with a DataSource name Northwind.
  22. //Your database name can be anyhting,
  23. //The datasource is most important here.
  24.  
  25.     String connectionURL = "jdbc:odbc:Northwind";
  26.     Connection connection=null;
  27.     try{
  28.  
  29. //Connect to the odbc driver specific to Sun Microsystems' platform(s)...
  30.  
  31.       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  32.       connection = DriverManager.getConnection(connectionURL, "root", "root");
  33.  
  34. //it is advisable to use a preparedStatement here, but this should do...
  35. //Begin running the query to retrieve userid and password info.
  36.  
  37.       Statement st = connection.createStatement();
  38.       ResultSet rs = st.executeQuery("Select * from YourTable");
  39.       while(rs.next()){
  40.  
  41. //add the result to an HTML page, no graphics, but you'll get the point...
  42.  
  43.         pw.println("YourName" + "   " + "YourPassword" + "<br>");
  44.         pw.println(rs.getString(1) + "   " + rs.getString(2) + "<br>");
  45.       }
  46.     }
  47.  
  48. //barring any unforseen adventures withe code, you should be good to go...
  49. //but in the case there are problems, it will be caught here.
  50. //Also see above where the exception is defined.
  51.  
  52.     catch (Exception e){
  53.       pw.println(e);
  54.     }
  55.   }
  56. }  
  57.  
We hope you have a bit of xml experience, you'll need it going forward. Below however is prety simple but needed to make available the servlet, in conjunction to the HTML gui:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?xml version="1.0" encoding="ISO-8859-1"?>
  3. <!--<!DOCTYPE web-app
  4.  PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  5.  "http://java.sun.com/dtd/web-app_2_3.dtd"> -->
  6.  
  7. <web-app>
  8.  <servlet>
  9.   <servlet-name>FancyServlet</servlet-name>
  10.   <servlet-class>YourServletName</servlet-class>
  11.  </servlet>
  12.  <servlet-mapping>
  13.  <servlet-name>FancyServlet</servlet-name>
  14.  <url-pattern>/YourServletName</url-pattern>
  15.  </servlet-mapping>
  16. </web-app> 
  17.  
  18.  
web.xml file is crucial to firing you HTML, without it your Servlet will not run...

Hope this is what you're looking for. I would also search here just to see if anything's posted.

In a bit!
Nov 20 '08 #2

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

Similar topics

1
3879
by: Hai Tran | last post by:
Any help is appreciated. Installed Tomcat 4.1 and Mysql on a WinXP. I've manage to get Tomcat up and was able to view my first application ( myhome ) simple home page. Tomcat was installed under...
2
2457
by: Rose Girl | last post by:
Hi Need some help on javascript. I need to know how to call a servlet from a javascript function. web-inf (jboss) path for servlet is: com.purpleace.ripple.admin.contacts.servlet.AdminReport...
7
3580
by: bylum | last post by:
Servlet SQLException Communication link failure java howto i can't connect jsp and database(mysql). This is the exception: exception org.apache.jasper.JasperException:...
14
2385
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...
0
2634
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...
6
4451
by: Sushmita | last post by:
hi all, I have wrriten code for a small web application. From my JSP page i am not able to call the servlet.. its throwing an exception. "javax.servlet.ServletException: Wrapper cannot find...
1
2133
by: shiyamala | last post by:
Hi i am shiyam, i am having some problem in java, i am basic java programmer. i have to write one program is writing the data into textfile name "newfile.txt" from one servlet and read it from...
2
3430
by: ManidipSengupta | last post by:
Hi, a few (3) questions for the Java experts, and let me know if this is the right forum. It deals with 100% java code (reason for posting here) but manages a Web browser with Javascript. Thanks in...
9
3152
by: mjahabarsadiq | last post by:
Hi I have created a servlet that is to be started at the server startup. And I got it. In that I have created a object of another class and set it as a session attribute. What I am trying is...
0
7260
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,...
0
7160
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...
0
7384
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,...
1
7099
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...
0
5685
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,...
1
5086
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
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...

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.