- Beranda
- Komunitas
- Tech
- Programmer Forum
HELP gan untuk masa depan ane :(


TS
Herdies
HELP gan untuk masa depan ane :(
Minta bantuan nya dong gans
, saya ada tugas kerja praktik bikin jsp, mau insert gk bisaq terus.
ane pake java netbeans.
Mohon bantuan nya gan, soal nya untuk masa depan ane


ane pake java netbeans.
Spoiler for home.jsp:
<form name="formuser" action="controler?/com/fwd/issuenotes/action=userImplemen" role="form" action="" method="post">
<!-- text input -->
<div class="form-group">
<table class="table">
<tr>
<td><label>User ID</label></td>
<td><input name="user_id" type="text" class="form-control" placeholder="" value="${user.idUser}"/>
</td>
</tr>
<tr>
<td><label>Password</label></td>
<td><input name="password" type="text" class="form-control" placeholder="" value="${user.pswrd}"/>
</td>
</tr>
<tr>
<td><label>User Type</label></td>
<td><input name="usertype" type="text" class="form-control" placeholder="" value="${user.type}"/>
</td>
</div></td>
<!-- /.input group -->
</div>
</td>
<td width="40%"> </td>
</tr>
<tr>
</tr>
<tr>
<td colspan=2 align="center">
<div class="box-footer">
<button type="submit" class="btn btn-primary" name="Insert" id="button">Submit</button>
<button type="submit" class="btn btn-primary" name="delete" id="button">Delete</button>
<button type="submit" class="btn btn-primary" name="update" id="button">Reset Password</button>
<button type="submit" class="btn btn-primary" name="btn1" id="button">Cancel</button>
</div>
</td>
</tr>
</table>
</div>
</form>
<!-- text input -->
<div class="form-group">
<table class="table">
<tr>
<td><label>User ID</label></td>
<td><input name="user_id" type="text" class="form-control" placeholder="" value="${user.idUser}"/>
</td>
</tr>
<tr>
<td><label>Password</label></td>
<td><input name="password" type="text" class="form-control" placeholder="" value="${user.pswrd}"/>
</td>
</tr>
<tr>
<td><label>User Type</label></td>
<td><input name="usertype" type="text" class="form-control" placeholder="" value="${user.type}"/>
</td>
</div></td>
<!-- /.input group -->
</div>
</td>
<td width="40%"> </td>
</tr>
<tr>
</tr>
<tr>
<td colspan=2 align="center">
<div class="box-footer">
<button type="submit" class="btn btn-primary" name="Insert" id="button">Submit</button>
<button type="submit" class="btn btn-primary" name="delete" id="button">Delete</button>
<button type="submit" class="btn btn-primary" name="update" id="button">Reset Password</button>
<button type="submit" class="btn btn-primary" name="btn1" id="button">Cancel</button>
</div>
</td>
</tr>
</table>
</div>
</form>
Spoiler for InsertUserServlet:
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class InsertUserServlet extends HttpServlet{
public void init(ServletConfig config) throws ServletException{
super.init(config);
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException{
String connectionURL = "jdbc:jtds:sqlserver://10.17.81.212/issuenotes";
Connection connection = null;
ResultSet rs;
res.setContentType("text/html");
String userid = req.getParameter("user_id");
String passwrd = req.getParameter("password");
String type = req.getParameter("usertype");
try {
// Load the database driver
Class.forName("com.sqlserver.jdbc.Connection");
// Get a Connection to the database
connection = DriverManager.getConnection(connectionURL,"sa","P@ssw0rd");
//Add the data into the database
PreparedStatement pst = connection.prepareStatement("INSERT into rf_user VALUES(?,?,?)");
pst.setString(1,userid);
pst.setString(2,passwrd);
pst.setString(3,type);
int numRowsChanged = pst.executeUpdate();
if(numRowsChanged!=0){
System.out.println("<br>Record has been inserted");
}
else{
System.out.println("failed to insert the data");
}
pst.close();
}
catch(ClassNotFoundException e){
System.out.println("Couldn't load database driver: " + e.getMessage());
}
catch(SQLException e){
System.out.println("SQLException caught: " + e.getMessage());
}
catch (Exception e){
System.out.println(e);
}
finally {
// Always close the database connection.
try {
if (connection != null) connection.close();
}
catch (SQLException ignored){
System.out.println(ignored);
}
}
}
}
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class InsertUserServlet extends HttpServlet{
public void init(ServletConfig config) throws ServletException{
super.init(config);
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException{
String connectionURL = "jdbc:jtds:sqlserver://10.17.81.212/issuenotes";
Connection connection = null;
ResultSet rs;
res.setContentType("text/html");
String userid = req.getParameter("user_id");
String passwrd = req.getParameter("password");
String type = req.getParameter("usertype");
try {
// Load the database driver
Class.forName("com.sqlserver.jdbc.Connection");
// Get a Connection to the database
connection = DriverManager.getConnection(connectionURL,"sa","P@ssw0rd");
//Add the data into the database
PreparedStatement pst = connection.prepareStatement("INSERT into rf_user VALUES(?,?,?)");
pst.setString(1,userid);
pst.setString(2,passwrd);
pst.setString(3,type);
int numRowsChanged = pst.executeUpdate();
if(numRowsChanged!=0){
System.out.println("<br>Record has been inserted");
}
else{
System.out.println("failed to insert the data");
}
pst.close();
}
catch(ClassNotFoundException e){
System.out.println("Couldn't load database driver: " + e.getMessage());
}
catch(SQLException e){
System.out.println("SQLException caught: " + e.getMessage());
}
catch (Exception e){
System.out.println(e);
}
finally {
// Always close the database connection.
try {
if (connection != null) connection.close();
}
catch (SQLException ignored){
System.out.println(ignored);
}
}
}
}
Spoiler for web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" >
<servlet>
<servlet-name>ControlerServlet</servlet-name>
<servlet-class>com.fwd.issuenotes.controler.ControlerServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>InsertMenuDataServlet</servlet-name>
<servlet-class>com.fwd.issuenotes.controler.InsertUserServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ControlerServlet</servlet-name>
<url-pattern>/controler</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>InsertMenuDataServlet</servlet-name>
<url-pattern>/insertuser</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>50</session-timeout>
</session-config>
</web-app>
<web-app version="3.1" >
<servlet>
<servlet-name>ControlerServlet</servlet-name>
<servlet-class>com.fwd.issuenotes.controler.ControlerServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>InsertMenuDataServlet</servlet-name>
<servlet-class>com.fwd.issuenotes.controler.InsertUserServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ControlerServlet</servlet-name>
<url-pattern>/controler</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>InsertMenuDataServlet</servlet-name>
<url-pattern>/insertuser</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>50</session-timeout>
</session-config>
</web-app>
Mohon bantuan nya gan, soal nya untuk masa depan ane





Diubah oleh Herdies 17-09-2015 14:43
0
841
Kutip
5
Balasan


Komentar yang asik ya
Urutan
Terbaru
Terlama


Komentar yang asik ya
Komunitas Pilihan