Save java files in CProgram FilesApache Software FoundationTomcat

Save java files in cprogram filesapache software

This preview shows page 32 - 56 out of 56 pages.

Save java files in “ C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\servlets-examples\WEB-INF\classes ” and, html files in “C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\servlets-examples”. In command prompt, go to java file path and compile the java code using command “javac filename.java”. If any errors, go to “edit filename.java”, debug and compile again. Now .class file get stored in the java file folder. First start the web server “apache”. Go to Apache Tomcat 5.5 in start menu path and click “Configure tomcat”. In a file names web.xml, in path “C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\servlets-examples\WEB-INF\” make one copy the <servlet> and <servlet-mapping> block and, Rename the javafile name to one you are running. If the Program as both java and html file, Run the HTML file by typing URL “; in browsers. If the program as only java file, Run the java file by typing URL “; in browser.
Image of page 32
Image of page 33
Image of page 34
Reading Data from a Client Servlets handles form data parsing automatically using the following methods: 1. getParameter() 2. getParameterValues() 3. getParameterNames() The doGet() and the doPost() method is called in the java servlet depending on the method used by the client.
Image of page 35
<html> <head> <title>Login</title> </head> <body> <h1>Login</h1> Please enter your username and password <form action="servlet/edu.albany.mis.goel.servlets.Login" method="POST"> <p><input type="text" name="username" length="40"> <p><input type="password" name="password" length="40"> <p><input type="submit" value="Submit"> </form> </body> </html>
Image of page 36
import javax.servlet.http.*; import java.io.*; public class Login extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse response) { // Get the parameter from the request String username = request.getParameter("username"); // Send the response back to the user try { response.setContentType("text/html"); PrintWriter writer = response.getWriter(); writer.println("<html><body>"); writer.println("Thank you, " + username + ". You are now logged into the system."); writer.println("</body></html>"); writer.close(); } catch (Exception e) { e.printStackTrace(); } } }
Image of page 37
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { doPost(request, response); }
Image of page 38
Reading HTTP Request Headers
Image of page 39
Image of page 40
Image of page 41
Image of page 42
Image of page 43
Image of page 44
Sending Data to a Client and Writing the HTTP Response Headers when a Web server responds to an HTTP request, the response typically consists of a status line, some response headers, a blank line, and the document.
Image of page 45
Image of page 46
Image of page 47
Image of page 48
Image of page 49
Image of page 50
Image of page 51
Image of page 57

You've reached the end of your free preview.

Want to read all 56 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes