Forums Register Login

How Set path of jsp file to open by servlet in netbeans web

+Pie Number of slices to send: Send
Hi,
I am trying to open jsp file by servlet. but it is not opening.. what is problem in this coding.. my database is saving well. I know how set html coding in servlet. but i wan display my result in just file

jsp file

<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Display User Master</title>
<link href="style/common.css" rel="stylesheet" type="text/css"/>
<link href="style/default.css" rel="stylesheet" type="text/css"/>
<link href="style/ServerControl.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<form name="frmUserMasterDisplay" method="GET">
<div id="dLogo">
<img id="Img1" alt="MTSU Logo" src="../MTSUJavaProject/images/top_banner.jpg" style="width: 100%;
height: 100px;" />
</div>
<div id="dMain" class="dMain" runat="server">
<div id="dBaseContainer" class="dBaseContainer" style="width:820px; position: absolute; margin-left: 220px;">
<div id="dHead" class="dHead" runat="server" style="background-color: Maroon; color: #FFFFFF;
width: 620px; margin-left: 100px; top: 50px; position: absolute; font-size: small;">
DISPLAY USER MASTER
</div>
<div id="dContiner" class="dContainer">
<div class="Box-Full">
<table border="1">
<thead>
<tr>
<th>User Id</th>
<th>Person Name</th>
<th>User Name</th>
<th>Password</th>
<th>Email ID</th>
</tr>
</thead>
<tbody>
<%
UserMasterViewLogic eb = new UserMasterViewLogic();
List<UserMasterEntity> list = eb.getEmployees();
for (UserMasterEntity e : list) {
%>
<tr>
<td><%= e.UserId %></td>
<td><%= e.PersonName%></td>
<td><%= e.UserName%></td>
<td><%= e.Password.toString() %></td>
<td><%= e.EmailID %></td>
</tr>
<%
}
%>
</tbody>
</table>
</div>
</div>
</div>
</div>
</form>
</body>
</html>

coding:
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import static java.lang.System.out;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author Shailin
*/
public class UserMasterLogic extends HttpServlet {

String PersonName,UserName,Password,EmailID;
String query,Selectquery;
Connection conn;
Statement smts;
ResultSet res;
Data dbConn;
int intAnswer;
UserMasterViewLogic userMasterViewLogic;
UserMasterEntity userMasterEntity;

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {

userMasterEntity = new UserMasterEntity();

dbConn = new Data();

conn = dbConn.SetConnetion();
smts = conn.createStatement();

userMasterEntity.PersonName = request.getParameter("tbPersonName");
userMasterEntity.UserName = request.getParameter("tbUserName");
userMasterEntity.Password = request.getParameter("tbPassword");
userMasterEntity.EmailID = request.getParameter("tbEmailID");

conn = dbConn.SetConnetion();
smts = conn.createStatement();

query = "Insert into Users(vPersonName, vUserName, vPassword, vEmailID)" +
" Values ('" + userMasterEntity.PersonName + "','" + userMasterEntity.UserName + "','" +
userMasterEntity.Password + "','" + userMasterEntity.EmailID+ "')";
intAnswer = smts.executeUpdate(query);

if(intAnswer == 1)
{
userMasterViewLogic = new UserMasterViewLogic();
userMasterViewLogic.getEmployees();
request.getRequestDispatcher("/UserMasterDisplay.jsp").forward(request, response);
}
else if(intAnswer == -1)
{
out.println("<body>");
out.println("<script type='text/javascript'>");
out.println("window.alert('Data Failed....')");
out.println("</script>");
out.println("</body>");
}
}catch(SQLException ex)
{
throw new ServletException(ex);
}finally
{
out.close();
}


}
Paper beats rock. Scissors beats tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 569 times.
Similar Threads
Value in the else condition is getting printed as the page loads
retriving values of hidden field and using it for retrieving data from database
utf-8 data with get method not working but post method working.
Value in the else condition is getting printed as the page loads
how to load a page properly ?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 23:46:47.