Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
- pageEncoding="ISO-8859-1"%>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
- <title>Author Details</title>
- </head>
- <body>
- <form method="post" action="http://localhost:8080/backend">
- Author ID : <input type="text" name="aid"/>
- <input type="submit" name="submit" id="submit"/>
- </form>
- </body>
- </html>
- <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
- pageEncoding="ISO-8859-1"%>
- <jsp:useBean id="testbean" scope="request" class=testbean />
- <%
- int aid = Integer.parseInt(request.getParameter("aid"));
- %>
- <jsp:setProperty name="testbean" property="aid" value=""/>
- <jsp:setProperty name="testbean" property=""/>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
- <title></title>
- </head>
- <body>
- Address : <jsp:setProperty property="aid" name="id"/><br>
- City : <jsp:setProperty property="aid" name="id"/>
- <br>
- State : ${state} <br>
- Zip : ${zip} <br>
- </body>
- </html>
- import java.sql.*;
- public class testbean
- {
- private String address, city, state;
- private int id, zip;
- private ResultSet rs;
- public String getAddress() {
- return address;
- }
- public void setAddress(String address) {
- this.address = address;
- }
- public String getCity() {
- return city;
- }
- public void setCity(String city) {
- this.city = city;
- }
- public String getState() {
- return state;
- }
- public void setState(String state) {
- this.state = state;
- }
- public int getId() {
- return id;
- }
- public void setId(int id) {
- this.id = id;
- }
- public int getZip() {
- return zip;
- }
- public void setZip(int zip) {
- this.zip = zip;
- }
- public ResultSet getRs(){
- return rs;
- }
- public void setRs(){
- try{
- Class.forName("com.mysql.jdbc.Driver");
- Connection con=DriverManager.getConnection("jdbc:mysql://localhost/TestProject?", "john", "root");
- PreparedStatement ps = con.prepareStatement("select * from author where aid=?");
- ps.setInt(1, id);
- ResultSet rs = ps.executeQuery();
- if(rs.next()){
- setId(rs.getInt(1));
- setAddress(rs.getString(2));
- setCity(rs.getString(3));
- setState(rs.getString(4));
- setZip(rs.getInt(5));
- }
- }
- catch(Exception ex){
- System.out.println(ex);
- }
- }
- }
Add Comment
Please, Sign In to add comment