I have three JSP as follows:
Employee_vendor_approve.jsp : which is retrieve Employee Details
update_employeeVendorLoginCredentials.jsp: Which is take reference of Employee_vendor_approve.jsp page for upadate process
update_process_employeeVendorLoginCredentials.jsp: is update retrieve data
from point 1 i can able to retrieve data but i unable to proceed point 2 and 3. where is problem i unable to find, when i click update link on Employee_vendor_approve.jsp, update_employeeVendorLoginCredentials.jsp showing blank here is my code
Employee_vendor_approve.jsp:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Employee and vendor approve Page</title>
</head>
<body>
<table border="1" align="center">
<tr>
<td>FIRST_NAME </td>
<td>LAST_NAME</td>
<td>ORGANIZATION_NAME</td>
<td>EMPLOYEE_ID</td>
<td>Approve</td>
<td>Status</td>
</tr>
<%
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con==DriverManager.getConnection("jdbc:oracle:thin:#173.18.114.213:1821:godb","ex","xe");
statement=con.createStatement();
String Sql="SELECT FIRST_NAME,LAST_NAME,ORGANISATION_NAME,EMPLOYEE_ID,APPROVE from REGISTRATION_EMPLOYEE where role in ('Employee','Vendor')";
resultSet=statement.executeQuery(Sql);
while(resultSet.next()){
%>
<tr>
<td><%=resultSet.getString("FIRST_NAME")%></td>
<td><%=resultSet.getString("LAST_NAME")%></td>
<td><%=resultSet.getString("ORGANISATION_NAME")%></td>
<td><%=resultSet.getString("EMPLOYEE_ID")%></td>
<td><%=resultSet.getString("APPROVE")%></td>
<td>
update
</td>
</tr>
<%
}
//con.close();
%>
</table>
</body>
</html>
update_employeeVendorLoginCredentials.jsp:
<html>
<body>
<form method="post" action="update_process_employeeVendorLoginCredentials.jsp">
<table border="1">
<tr>
<th>FIRST_NAME </th>
<th>LAST_NAME</th>
<th>ORGANIZATION_NAME</th>
<th>EMPLOYEE_ID</th>
<th>Approve</th>
</tr>
<%
String employee_id=request.getParameter("employee_id");
int sumcount=0;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:#173.18.114.213:1821:godb","ex","xe");
Statement st=con.createStatement();
String query="SELECT FIRST_NAME,LAST_NAME,ORGANISATION_NAME,EMPLOYEE_ID,APPROVE from REGISTRATION_EMPLOYEE where EMPLOYEE_ID="+employee_id;
ResultSet rs=st.executeQuery(query);
while(rs.next())
{
%>
<tr>
<td><input type="text" name="FIRST_NAME" value="<%=rs.getString("FIRST_NAME")%>"> </td>
<td><input type="text" name="LAST_NAME" value="<%=rs.getString("LAST_NAME")%>"> </td>
<td><input type="text" name="ORGANISATION_NAME" value="<%=rs.getString("ORGANISATION_NAME")%>"> </td>
<td><input type="text" name="APPROVE" value="<%=rs.getString("APPROVE")%>"> </td>
<td><input type="hidden" name="EMPLOYEE_ID" value="<%=rs.getString(1)%>"></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Update" style="background-color:#49743D;font-weight:bold;color:#ffffff;"></td>
</tr>
<% }
}
catch(Exception ex)
{
}
%>
</table>
</form>
</body>
</html>
update_process_employeeVendorLoginCredentials.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:#173.18.114.213:1821:godb","ex","xe");
String EMPLOYEE_ID=request.getParameter("EMPLOYEE_ID");
String first_name=request.getParameter("FIRST_NAME");
String Last_name=request.getParameter("LAST_NAME");
String ORGANISATION_NAME=request.getParameter("ORGANISATION_NAME");
String Approve_status=request.getParameter("APPROVE");
if (EMPLOYEE_ID!=null)
{
// Connection con = null;
PreparedStatement ps = null;
int personID = Integer.parseInt(EMPLOYEE_ID);
try
{
String Sql="update REGISTRATION_EMPLOYEE set APPROVE='Y' where EMPLOYEE_ID="+EMPLOYEE_ID;
ps=con.prepareStatement(Sql);
ps.setString(1, Approve_status);
int i=ps.executeUpdate();
if(i>0)
{
out.print("Record Updated Successfully");
}
else
{
out.print("There is a problem in updating Record.");
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
%>
</body>
</html>
In Employee_vendor_approve.jsp: you set parameter name called id
update
but in update_employeeVendorLoginCredentials.jsp you get the parameter via employee_id
String employee_id=request.getParameter("employee_id");
They do not keep the same,so you get empty value.In order to solve this,you can change it to below:
String employee_id=request.getParameter("id");//using id instead of employee_id
To the problem you can not update data,it's also due to you fetch wrong value in update_employeeVendorLoginCredentials.jsp:
<td><input type="hidden" name="EMPLOYEE_ID" value="<%=rs.getString(1)%>"></td> // you have get the wrong value for id
In order to let it work,change it as below:
<td><input type="hidden" name="EMPLOYEE_ID" value="<%=rs.getString("EMPLOYEE_ID")%>"></td>
Related
There are two tables in my database (filedetails and filestatus).
I using the following code to insert value in filedetails table.
In filestatus table i have 3 columns
filenumber,
fdepartment,
status(either in or out).
In my status.jsp page I have given 3 dropdown list in which 2 dropdownlist take filenumber and department from filedetails table and 1 takes status(which is either IN or OUT).
If status is OUT values are simply inserted in filestatus table but if it is in the values are inserted into filestatus and department corresponding to filenumber gets updated.
The problem is the filenumber, if i use the following code to insert filenumber then how will i update the file number ?
Is ther some other way to do this?
file.jsp
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert File Page</title>
<style>
header {
background-color:teal;
color:white;
text-align:center;
padding:30px;
}
section {
width:350px;
float:left;
padding:150px;
}
footer {
background-color:black;
color:white;
clear:both;
text-align:center;
padding:5px;
}
</style>
</head>
<body style="background-color:lightsteelblue;">
<%
String userName = null;
String sessionID = null;
Cookie[] cookies = request.getCookies();
if(cookies !=null){
for(Cookie cookie : cookies){
if(cookie.getName().equals("user")) userName = cookie.getValue();
}
}
%>
<header>
<h3>Hi <%=userName %></h3>
</header>
<font color="black">back</font>
<form action=" LogoutServlet" method="post">
<input type="submit" value="Logout" >
</form>
<section>
<form action="FileServlet" method="post">
<h3>Insert File Details</h3>
<table border="1">
<tbody>
<tr>
<td>File Name :</td>
<td><input type="text" name="filename" value="" size="50" /></td>
</tr>
<tr>
<td>File Type</td>
<td><input type="text" name="type" value="" size="50" /> </td>
</tr>
<tr>
<td>Place of Origin(company) :</td>
<td><input type="text" name="company" value="" size="50" /></td>
</tr>
<tr>
<td>HeadOffice :</td>
<td><input type="text" name="HO" value="" size="50" /> </td>
</tr>
<tr>
<td>File Location :</td>
<td><input type="text" name="department" value="" size="50" /> </td>
</tr>
<tr>
<td>Subject :</td>
<td><input type="text" name="subject" value="" size="50" /></td>
</tr>
<tr>
<td>File Number :</td>
<td><input type="text" name="fileno" value="" size="50" /></td>
</tr>
</tbody>
</table>
<input type="reset" value="Clear" name="Clear" />
<input type="submit" value="Submit" name="Submit" />
</form>
</section>
<footer>
Copyright 2008 NSIC. All right reserved.
</footer>
</body>
</html>
fileServlet.java
package bean;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class FileServlet extends HttpServlet {
#Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Cookie[] cookies = request.getCookies();
if(cookies != null){
for(Cookie cookie : cookies){
if(cookie.getName().equals("JSESSIONID")){
System.out.println("JSESSIONID="+cookie.getValue());
break;
}
}
}
HttpSession session = request.getSession(false);
System.out.println("User="+session.getAttribute("user"));
if(session!=null && session.getAttribute("user") != null){
String user=(String)session.getAttribute("user");
boolean status=false;
try{
String fname=request.getParameter("name");
String type=request.getParameter("type");
String company=request.getParameter("department");
String headoffice=request.getParameter("HO");
String location=request.getParameter("department");
String subject=request.getParameter("subject");
String fno=company+"/"+headoffice+"/"+location+"/"+type+"/"+fname;
Connection con=ConnectionProvider.getCon();
String sql="insert into files(fileno,fname,ftype,subject,company,headoffice,fdepartment) values (?,?,?,?,?,?)";
PreparedStatement pstmt =con.prepareStatement(sql);
pstmt.setString(1,fno);
pstmt.setString(2,fname);
pstmt.setString(3,type);
pstmt.setString(4,subject);
pstmt.setString(5,company);
pstmt.setString(6,headoffice);
pstmt.setString(7,location);
int rs=pstmt.executeUpdate();
if(rs>0){status=true;}
}catch(Exception e){System.out.println(e);}
if(status){
PrintWriter out= response.getWriter();
out.println("Values have been inserted"+user);
response.sendRedirect("create1.jsp");
}
else
{
PrintWriter out= response.getWriter();
out.println("failed");
response.sendRedirect("create1.jsp");
}
}else{
RequestDispatcher rd = getServletContext().getRequestDispatcher("/index.html");
PrintWriter out= response.getWriter();
out.println("<font color=red>Either user name or password is wrong.</font>");
rd.include(request, response);
}
}
}
There is create.jsp which gives link to choose for filedetails.jsp or status.jsp
status.jsp
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%# page import ="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>File Status Page</title>
<style>
header {
background-color:teal;
color:white;
text-align:center;
padding:30px;
}
section {
width:350px;
float:left;
padding:150px;
}
footer {
background-color:black;
color:white;
clear:both;
text-align:center;
padding:5px;
}
</style>
</head>
<body style="background-color:lightsteelblue;">
<%
String userName = null;
String sessionID = null;
Cookie[] cookies = request.getCookies();
if(cookies !=null){
for(Cookie cookie : cookies){
if(cookie.getName().equals("user")) userName = cookie.getValue();
}
}
%>
<header>
<h3>Hi <%=userName %></h3>
</header>
<font color="black">back</font>
<form action=" LogoutServlet" method="post">
<input type="submit" value="Logout" >
</form>
<section>
<h3>Change Status</h3>
<form action="statusServlet" method="post">
<select name="files">
<%
try{
String sql="select * from files";
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/login",
"root", "root");
Statement st = con.createStatement();
ResultSet rs=st.executeQuery(sql);
while(rs.next()){
%>
<option value="<%=rs.getInt("fileno")%>"><%=rs.getString("fname")%></option>
<%}
rs.close();
st.close();
con.close();
}catch(Exception e){
e.printStackTrace();
}
%>
</select>
<select name="departments">
<%
try{
String sql="select * from department";
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/login",
"root", "root");
Statement st = con.createStatement();
ResultSet rs=st.executeQuery(sql);
while(rs.next()){
%>
<option value="<%=rs.getInt("departmentid")%>"><%=rs.getString("departmentname")%></option>
<%}
rs.close();
st.close();
con.close();
}catch(Exception e){
e.printStackTrace();
}
%>
</select>
<select name="input">
<option>IN</option>
<option>OUT</option>
</select>
<input type="submit" value="submit" name="submit" />
</form>
</section>
<footer>
Copyright 2008 NSIC. All right reserved.
</footer>
</body>
</html>
I have not yet created statusServlet.java
I will seperate department into two parts like below.
1) Department from which the file is being originated
2) Current location of file.
I will use the file origin department for generating the filenumber and will update the current location separately (Initially the current location will be same as origin department).
If anyone having more effective way than this, then I will accept that too.
I'm a beginner programmer, I already build page for data entry and page show all entries, but now I want to show specific row inside the table, which code can help me?
My table columns: fullname - email - Phone - education
I want to search by email to show the other data in one page.
I found this code on internet:
<%#page import="java.sql.*"%>
<% Class.forName("com.mysql.jdbc.Driver");%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%!
public class Showit {
String URL = "jdbc:mysql://localhost/regdata";
String USERNAME = "root";
String PASSWORD = "admin";
Connection conn = null;
PreparedStatement selectRegister = null;
ResultSet resultSet = null;
public Showit() {
try {
conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
selectRegister = conn.prepareStatement(
"SELECT a.fullname, a.email,"
+ " FROM mainr a,"
+ "WHERE a.fullname = ?"
+ "AND a.email = ?");
} catch (Exception e) {
e.printStackTrace();
}
}
public ResultSet getShowit(String fullname, String email) {
try {
selectRegister.setString(1, fullname);
selectRegister.setString(2, email);
resultSet = selectRegister.executeQuery();
} catch (Exception e) {
e.printStackTrace();
}
return resultSet;
}
}
%>
<%
String fullname = new String();
String email = new String();
if (request.getParameter("fullname") != null) {
fullname = request.getParameter("fullname");
}
if (request.getParameter("email") != null) {
fullname = request.getParameter("email");
}
Showit showit = new Showit();
ResultSet showits = showit.getShowit(fullname, email);
%>
<table border="1">
<tbody>
<tr>
<td>Full Name</td>
<td>Email</td>
<td>Title</td>
</tr>
<% while (showits.next()) {%>
<tr>
<td><%= showits.getString("fullname")%></td>
<td><%= showits.getString("email")%></td>
<td><%= showits.getString("Phone")%></td>
</tr>
<% }%>
</tbody>
</table>
</body>
</html>
which connect with this page:
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%#page import="java.sql.*"%>
<%#page import="java.util.Scanner" %>
<% Class.forName("com.mysql.jdbc.Driver");%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Search</title>
</head>
<body>
<form name="search" action="display.jsp" method="POST">
<table border="0">
<tbody>
<tr>
<td>Full Name</td>
<td><input type="text" name="fullname" value="" size="50" /></td>
</tr>
<tr>
<td>E-Mail</td>
<td><input type="text" name="email" value="" size="50" /></td>
</tr>
</tbody>
</table>
<input type="reset" value="Reset" name="reset" />
<input type="submit" value="Submit" name="Submit" />
</form>
</body>
</html>
but it's not work.
The issue may be with this line:
fullname = request.getParameter("email");
Note that you are assigning the email parameter to the fullname variable.
first what i see is that the Query is wrong. Remove the , after the table alias "a" (here line 2) like this:
"SELECT a.fullname, a.email,"
+ " FROM mainr a"
+ "WHERE a.fullname = ?"
+ "AND a.email = ?");
There is also an issue here:
<td><%= showits.getString("Phone")%></td>
You did not include Phone in the SELECT statement, so it will not exist in the ResultSet.
I've created a login environment using jsp. index.jsp, login.jsp. I take username and password from database. If user name and password matches with the database it does login process perfectly. When user give wrong name or password it shows a error message invalid name or passwordand redirect to the login page. Nothing's wrong, but I am facing a problem when I login first. The place where the error message is shown after submitting wrong name or password that place is showing null.
Why null is showing?
Below is my code
index.jsp
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Example</title>
</head>
<body>
<form action="login.jsp" method="post">
<center>
<table border="1" width="30%" cellpadding="3">
<thead>
<tr>
<th colspan="2" align ="left">Login Here</th> <h5><%=request.getAttribute("errorMessage")%> </h5>
</tr>
</thead>
<tbody>
<tr>
<td>User Name</td>
<td><input type="text" name="uname" value="" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="pass" value="" /></td>
</tr>
<tr>
<td><input type="submit" value="Login" /></td>
<td><input type="reset" value="Reset" /></td>
</tr>
</tbody>
</table>
</center>
</form>
</body>
</html>
login.jsp
<%# page import ="java.sql.*" %>
<%
String userid = request.getParameter("uname");
String pwd = request.getParameter("pass");
Class.forName("org.postgresql.Driver");
Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/test", "postgres", "root");
Statement st = con.createStatement();
ResultSet rs;
rs = st.executeQuery("select * from member where uname='" + userid + "' and pass='" + pwd + "'");
if (rs.next()) {
session.setAttribute("userid", userid);
response.sendRedirect("success.jsp");
} else {
request.setAttribute("errorMessage", "Invalid user or password");
request.getRequestDispatcher("/index.jsp").forward(request, response);
}
%>
You can use this in your index.jsp
<% if ((String) request.getAttribute("errorMessage") != null) {%>
<h3 style="color: red;"><%=(String) request.getAttribute("errorMessage")%></h3>
<%
}
%>
Instead of this
<%=request.getAttribute("errorMessage")%>
please check condition before showing error, if request parameter is null then it should not be rendered else it would be rendered, modify you code according to below snippet
<thead>
<tr>
<th colspan="2" align ="left">Login Here</th>
<h5>
<%if(request.getParameter("errorMessage")!=null){%>
<%=request.getParameter("errorMessage")%><%}%>
</h5>
</tr>
</thead>
The errorMessage attribute will not be available in request for the first time. Kindly check for a null and then display the message.
<%=request.getAttribute("errorMessage")%>
The below piece of code could help you.
<tr>
<th colspan="2" align ="left">Login Here</th>
<h5>
<%
String errorMsg = request.getAttribute("errorMessage");
if (errorMsg != null) {
%>
<%=errorMsg%>
<%
}
%>
</h5>
</tr>
As errorMessage attribute is null in the request when you load it first time, so you are getting null. You need to add null check for it. You can do this way
<th colspan="2" align ="left">Login Here</th>
<% if (request.getAttribute("errorMessage") != null) {
out.println("<h5>" + request.getAttribute("errorMessage") + "</h5>");
}%>
Correct your code in login.jsp
write session.setAttribute("errorMessage", "Invalid user or password");
instead of request.setAttribute("errorMessage", "Invalid user or password");
..
null message show because of this.
can you help me resolve my problem?I use JSP to update but no action be occurred(insert and delete be OK).For example,I update cname from ASUS to SONY but when click on Update button,cname still be ASUS.
note that cid is auto_increment
Here is update method in DAO
public int updateComputer(Computer com) {
int n = 0;
try {
String sql = "UPDATE Computer SET cname=?, quantity=?, price=?,functions=? where cid=?";
PreparedStatement preparedStatement = conn.prepareStatement(sql);
// Parameters start with 1
preparedStatement.setString(1, com.getCname());
preparedStatement.setInt(2, com.getQuantity());
preparedStatement.setDouble(3, com.getPrice());
preparedStatement.setString(4, com.getFunc());
n = preparedStatement.executeUpdate();
} catch (SQLException ex) {
Logger.getLogger(ComputerDAO.class.getName()).log(Level.SEVERE, null, ex);
}
return n;
}
here is updateComputer.jsp
<%#page import="java.sql.ResultSet"%>
<%#page import="dao.ComputerDAO"%>
<%#page import="entity.Computer"%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
ComputerDAO comDAO = new ComputerDAO();
String cid = request.getParameter("cid");
ResultSet rs = comDAO.getData("Select * from Computer where cid=" + Integer.parseInt(cid));
Computer com = new Computer();
if (rs.next()) {
int id = rs.getInt(1);
String cname = rs.getString(2).trim();
int quan = rs.getInt(3);
double price = rs.getDouble(4);
String func = rs.getString(5).trim();
com = new Computer(id, cname, quan, price, func);
}
%>
<form name="form1" method="post" action="ProcessUpdateComputer.jsp">
<table width="400" height="252" border="0" align="center" cellpadding="2" cellspacing="2">
<caption>
<h2>Update Computer</h2>
</caption>
<tr>
<th width="29%" align="left" scope="row">Computer ID</th>
<td width="71%">
<input type="text" name="cid" id="cid" disabled="" value="<%= com.getCid()%>"></td>
</tr>
<tr>
<th width="29%" align="left" scope="row">Computer Name</th>
<td width="71%">
<input type="text" name="cname" id="cname" value="<%=com.getCname()%>"></td>
</tr>
<tr>
<th align="left" scope="row">Quantity</th>
<td>
<input type="text" name="quantity" id="quantity" value="<%=com.getQuantity()%>"></td>
</tr>
<tr>
<th align="left" scope="row">Price</th>
<td>
<input type="text" name="price" id="price" value="<%= com.getPrice()%>"></td>
</tr>
<tr>
<th align="left" scope="row">Functions</th>
<td>
<!--<input type="text" name="functions" id="functions" value="<%=com.getFunc()%>"></td>-->
<textarea name="functions" rows="8" id="functions" value="<%=com.getFunc()%>"></textarea></td>
</tr>
<tr>
<th align="right" scope="row"></th>
<td><input type="submit" name="button" id="button" value="Update">
<input type="hidden" name="service" id="service" value="<%= cid%>"></td>
</tr>
</table>
<p align="center">View Computer List</p>
</form>
</body>
</html>
Here is ProcessUpdateComputer.jsp
<%#page import="entity.Computer"%>
<%#page import="dao.ComputerDAO"%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
ComputerDAO dao = new ComputerDAO();
String cname = request.getParameter("cname");
String quan = request.getParameter("quantity");
String price = request.getParameter("price");
String func = request.getParameter("functions");
int uquan = Integer.parseInt(quan);
double uprice = Double.parseDouble(price);
Computer com = new Computer(0, cname, uquan, uprice, func);
int i = dao.updateComputer(com);
if (i > 0) {
out.println("updated");
}
%>
<p>View Computer List</p>
</body>
</html>
Here you're missing the fifth parameter, the cid:
String sql = "UPDATE Computer SET cname=?, quantity=?, price=?,functions=? where cid=?";
PreparedStatement preparedStatement = conn.prepareStatement(sql);
// Parameters start with 1
preparedStatement.setString(1, com.getCname());
preparedStatement.setInt(2, com.getQuantity());
preparedStatement.setDouble(3, com.getPrice());
preparedStatement.setString(4, com.getFunc());
preparedStatement.setString(5, com.getId());
n = preparedStatement.executeUpdate();
Here is not clear what you want to do, are you always trying to update the computer with cid=0?
Computer com = new Computer(0, cname, uquan, uprice, func);
int i = dao.updateComputer(com);
You'll probably want to retrieve the cid from the request, like the other params
String cid = request.getParameter("cid");
Iam working on a project in JSP using netbeans.
Iam getting the following error......but i didn't find the java any files..please provide me something.The error is:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 205 in the generated java file
Syntax error, insert "Finally" to complete TryStatement
An error occurred at line: 206 in the generated java file
Syntax error, insert "}" to complete ClassBody
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:589)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
The files i used are:
addNewUser.jsp:
<%# page language="java" %>
<%# page session="true" %>
<%# page import="java.util.*" %>
<HTML>
<head>
<LINK href="styles.css" type="text/css" rel="stylesheet">
</head>
<SCRIPT LANGUAGE="JavaScript">
<!--
history.go(+1);
function validate(){
x = document.NewUser.uid;
y = document.NewUser.pwd;
z = document.NewUser.auth;
var ed=x.value;
var pd=y.value;
var ad=z.value;
var pattern = /^([a-zA-Z0-9\_\.]{4,10})$/;
var Apattern = /^([0-3]{1})$/;
if(!(pattern.test(ed))){
alert("Invalid username");
return false;
}
else if(!(pattern.test(pd))){
alert("Invalid password");
return false;
}
else if(!(Apattern.test(ad))){
alert("Invalid Authentication");
return false;
}
else
return true;
}
//-->
</SCRIPT>
<br><br>
<body Class=Grad>
<center>
<BR><BR><br><br>
<FONT FACE="Century Gothic">
<FONT size="2" color="blue" FACE="Century Gothic">
<FORM NAME="NewUser" ACTION="AddNewUser1.jsp" METHOD="POST" onsubmit="return validate()">
<TABLE Border=0 align=center>
<TR class=row_title ALIGN="center">
<TH COLSPAN="2"> Add user</TH>
</TR>
<TR class=row_even>
<TD>UserID * </TD>
<TD><input TYPE=text name=uid size="10" maxlength="10"></TD>
</TR>
<TR class=row_odd>
<TD>Password * </TD>
<TD><input TYPE=password name=pwd size="10" maxlength="20"></TD>
</TR>
<TD><input type=hidden name=auth value=2>
<TR class=row_even>
<TD><INPUT TYPE=submit name=submit value="Submit">
</TD>
<TD><INPUT TYPE=reset name=resett value="Reset" >
</TD>
</TR>
</TABLE>
<A align="center" href="Login.jsp">BACK TO HOME</A>
</FORM>
</BODY>
</HTML>
addNewUser1.jsp:
<%# page language="java" %>
<%# page session="true" %>
<%# page import="java.sql.*" %>
<%# page import="java.io.*" %>
<%# page import="java.util.Random" %>
<html>
<head>
<LINK href="styles.css" type="text/css" rel="stylesheet">
<SCRIPT LANGUAGE="JavaScript">
<!--
history.go(+1);
//-->
</SCRIPT>
</head>
<jsp:include page="MultiLevelmenu.htm"/><br><br><body Class=SC>
<center>
<BR><BR>
<FONT FACE="Century Gothic">
<!--Declaration of varaibles-->
<%! String errormsg ;%>
<%! String disluserid ;%>
<%! String dislpwd ;%>
<%! int auth ;%>
<%
/*Retreiving user id and password*/
disluserid = request.getParameter("uid");
if(disluserid == null)
disluserid = "";
dislpwd = request.getParameter("pwd");
if(dislpwd == null)
dislpwd = "";
String sauth = request.getParameter("auth");
if(sauth == null)
auth=0;
auth = Integer.parseInt(sauth);
//System.out.println(disluserid+dislnewpwd+dislpwd);
%>
<%
/*Declaration of variables*/
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
String Userid,Password;
try
{
/*Getting the connection variable from session*/
con=(Connection)session.getAttribute("connection");
stmt = con.createStatement();
String Query = "SELECT * from student where studentid = \'"+disluserid+"\'";
System.out.println(Query);
rs = stmt.executeQuery(Query);
}
catch(Exception e)
{
System.out.println("Exception"+e);
/* If user provides valid username & password then update the new password to database*/
if(rs.next())
{%>
<script>
for(i=1;i<=6;i++) document.write("<br>");
</script>
<H3 align="center"> User already exists</H3>
<BR>
<center>
Back
</center>
<%
}
else{
String UpdateQuery =
"Insert into student values(\'"+disluserid+"\',\'"+dislpwd+"\',"+auth+")";
//System.out.println(UpdateQuery);
int rowsAffected=stmt.executeUpdate(UpdateQuery);
//System.out.println("Rows Affected = " + rowsAffected);
if(rowsAffected==1)
{%>
<script>
for(i=1;i<=10;i++) document.write("<br>");
</script>
<H3 align="center">User Created Successfully </H3>
Create Another User
<br/>
Home
<BR>
<%}
/* If user provides invalid password or username*/
else{%>
<script>
for(i=1;i<=6;i++) document.write("<br>");
</script>
<H3 align="center">Unable to create user please try again </H3>
<BR>
<% } %>
<%
}
%>
</FONT>
</center>
</BODY>
</html>
try {
/*Getting the connection variable from session*/
con=(Connection)session.getAttribute("connection");
stmt = con.createStatement();
String Query = "SELECT * from student where studentid = \'"+disluserid+"\'";
System.out.println(Query);
rs = stmt.executeQuery(Query);
} catch(Exception e) { System.out.println("Exception"+e);
In the above code section you are not completing the try's catch block.