This question already has answers here:
Browser can't access/find relative resources like CSS, images and links when calling a Servlet which forwards to a JSP
(9 answers)
Closed 5 years ago.
my code is
AddBookCategory.java
package com.bhim.admin;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.bhim.dbConnection.DBConnection;
#WebServlet(name = "category", urlPatterns = "/addCategory")
public class AddBookCategory extends HttpServlet {
#Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)throws
ServletException, IOException {
// for checking
System.out.println("reached here...");
DBConnection dbConnection=new DBConnection();
try {
dbConnection.open();
String query="insert into `bookcategory`(`c_name`) values(?)";
PreparedStatement preparedStatement=dbConnection.gePreparedStatement(query);
preparedStatement.setString(1, req.getParameter("category"));
int i=preparedStatement.executeUpdate();
if(i>0) {
System.out.println("Insert Successfully");
// req.getRequestDispatcher("admin/addCategory.jsp").forward(req, resp);
resp.sendRedirect("admin/addCategory.jsp");
}
else{
System.out.println("insertion Failed...");
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e)
e.printStackTrace();
}
}
}
addCategory.jsp
<jsp:include page="adminHeader.jsp" />
<center>
<div class="content">
<form action="${pageContext.request.contextPath}/addCategory" method="get">
<table class="full" border="0">
<tr>
<td><h2>Category Name</h2></td>
</tr>
<tr>
<td><input type="text" name="category" /></td>
</tr>
<tr>
<td><input type="submit" value="Add Category" /></td>
</tr>
</table>
</form>
</div>
</center>
<jsp:include page="../footer.jsp" />
adminheader.jsp
<!DOCTYPE html>
<html>
<head>
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<title>Bus Booking System</title>
</head>
<body>
<div id='wrapper'>
<div class="banner">
<h1>Online Library Management System</h1>
<% // Using session...
HttpSession session1 = request.getSession();
String user = (String) session1.getAttribute("user");
%>
<span class="session"> Welcome:<%=user%>
</span>
</div>
<div class="menu">
<ul>
<li>Home</li>
<li>Book Category</li>
<li>Books</li>
<li> User Mgmt</li>
<li>Search Book </li>
<li>Check allocated Book</li>
<li> Notification</li>
<li>Logout
</li>
</ul>
</div>
I am trying to forward page from servlet to jsp using RequestDispatcher CSS is not work but i also try sendRedirect css is working.Give me suggestion why css is not working when using requestDispatcher.
The problem I found was in the way you include your css file. If you debug it using Chrome you should see a 404 error loading the style.css file. Try this:
addCategory.jsp
<!DOCTYPE html>
<html>
<head>
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<title>Bus Booking System</title>
</head>
<body>
<jsp:include page="adminHeader.jsp" />
<center>
<div class="content">
<form action="${pageContext.request.contextPath}/addCategory" method="get">
<table class="full" border="0">
<tr>
<td><h2>Category Name</h2></td>
</tr>
<tr>
<td><input type="text" name="category" /></td>
</tr>
<tr>
<td><input type="submit" value="Add Category" /></td>
</tr>
</table>
</form>
</div>
</center>
<jsp:include page="../footer.jsp" />
adminHeader.jsp
<div id='wrapper'>
<div class="banner">
<h1>Online Library Management System</h1>
<% // Using session...
HttpSession session1 = request.getSession();
String user = (String) session1.getAttribute("user");
%>
<span class="session"> Welcome:<%=user%>
</span>
</div>
<div class="menu">
<ul>
<li>Home</li>
<li>Book Category</li>
<li>Books</li>
<li> User Mgmt</li>
<li>Search Book </li>
<li>Check allocated Book</li>
<li> Notification</li>
<li>Logout
</li>
</ul>
</div>
Related
I can't get the Quill editor to appear.
I have two ejs files, a layout and an add_new(which includes the layout).
layout.ejs
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%= title %> </title>
<link rel="stylesheet" href="/css/normalize.css">
<link rel="stylesheet" href="/css/skeleton.css">
<link rel="stylesheet" href="/css/styles.css">
<link href="https://cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet">
</head>
<body>
<header class="interface-header">
<h3 class="interface-title">
<a href="/admin" id="interface-title">
Διαχείρηση
</a>
</h3>
<nav class="interface-nav">
<ul class="interface-navbar-list">
<li class="navbar-item">
<a href="/admin/post/addNew" target="_blank" class="navbar-link button button-primary">
Δημιουργία
</a>
</li>
<li class="navbar-item">
<a href="/" target="_blank" class="navbar-link button">
Ιστοσελίδα
</a>
</li>
<li class="navbar-item">
<a href="/login/logout" class="navbar-link button-danger">
Αποσύνδεση
</a>
</li>
</ul>
</nav>
</header>
</body>
</html>
add_new.ejs
<%- include("interface_layout.ejs") %>
<div class="container">
<form action="/admin/posts" method="POST" enctype="multipart/form-data" class="admin-form">
<label for="title">Τίτλος</label>
<input type="text" name="title" id="title" class="u-full-width">
<label for="content">Περιεχόμενο</label>
<textarea name="content" id="content" rows="20" style="display: none;" class="u-full-width"></textarea>
<div id="toolbar"></div>
<div id="editor"><p>hello world</p></div>
<% const choices = ["Συνεντεύξεις", "Θέατρο-Κριτική", "Εικαστικά", "test-ride"] %>
<label>Ετικέτες</label>
<div class="choices">
<% choices.forEach(choice => { %>
<label for="<%= choice %>" class="choice"><%= choice %></label>
<input type="checkbox" id="<%= choice %>" value="<%= choice %>" name="tags" class="switch">
<% }) %>
</div>
<label for="date">Ημερομηνία αρχικής δημοσίευσης</label>
<input type="date" name="publishingDate" i="date">
<label for="image">Εικόνα</label>
<input type="file" name="image" id="image" accept="iamge/gif, image/png, image/jpeg">
<button class="button-primary button" type="submit">Ανέβασμα</button>
</form>
</div>
<script src="https://cdn.quilljs.com/1.3.6/quill.js"></script>
<!-- Initialize Quill editor -->
<script>
var options = {
debug: "info",
modules: {
toolbar: "#toolbar"
},
placeholder: "Compose an epic...",
readOnly: true,
theme: "snow"
}
var container = document.getElementById("editor");
var quill = new Quill(container, options);
</script>
I'm trying to first use quill using the cdn. I import the css for the snow theme in my layout.ejs and in the end of add_new.ejs i import quill and then I initialize it with a script tag. I can't get it to appear.
My console gives me this:
Content Security Policy: The page’s settings blocked the loading of a
resource at https://cdn.quilljs.com/1.3.6/quill.js (“script-src”).
I have also tried to "const Quill = require("quill")" in my routes.js and pass the editor as a variable to my view but I get.
var elem = document.createElement('div');
^
ReferenceError: document is not defined
at Object. (/node_modules/quill/dist/quill.js:7661:12)
I tried the quickstart method (on quill's website) on a plain index.html file and a basic express project with one ejs file and quill worked both times. I suspect there is something wrong with the includes/templates?
I get an error when viewing the browser console, what you need to do is put the highlight.min.js file in front of quill.js. Best to download locally
<link href="/css/quill_editor/quill.snow.css" rel="stylesheet">
<script src="/js/quill_editor/highlight.min.js"></script>
<script src="/js/quill_editor/quill.js"></script>
Below I have Displayed how exactly we can send data from quill/ejs to any backend.
<!-- Include stylesheet -->
<link
href="https://cdn.quilljs.com/1.3.6/quill.snow.css"
rel="stylesheet">
<form action="/add-quill" method="post">
<div id="editor">
</div>
<input name="about" type="hidden">
<input type="submit" onclick="myFunction()">
</form>
<!-- Create the editor container -->
<!-- Include the Quill library -->
<script
src="https://cdn.quilljs.com/1.3.6/quill.js"></script>
<!-- Initialize Quill editor -->
<script>
function myFunction() {
<!-- Here the class ql-editor is defined by quill js, we can access the inner html from here -->
var editor = document.getElementsByClassName('ql-editor')[0].innerHTML
var about = document.querySelector('input[name=about]');
about.value = editor
};
//Configuring quill
var quill = new Quill('#editor', {
theme: 'snow'
});
</script>
I am trying to Remove a topic from CrudRepository, but the checkboxes I am trying to create don't show up.
I have an Add Method which works just fine, but the remove doesn't.
HTML: hello.html
for the navigation and head fragments
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org/"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head th:fragment="head">
<title> Lunch Planner Beta </title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" type="text/css"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"> </script>
</head>
<body>
<h1 th:inline="text">Hello [[${#httpServletRequest.remoteUser}]]!</h1>
<nav th:fragment="navigation">
List |
Add |
<a th:href="/removeTopic">Remove</a>
</nav>
<form th:action="#{/home}" method="get">
<input type="submit" value="Home"/>
</form>
<br/>
<form th:action="#{/logout}" method="post">
<input type="submit" value="Sign OUT"/>
</form>
</body>
</html>
The part of TopicController.java
#RequestMapping(method = RequestMethod.POST, value = "/remove", consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE})
#Transactional
public ModelAndView deleteTopic(Long id, HttpServletResponse response, Errors errors){
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
model.addObject("topic",topicService.getTopic(id));
topicService.deleteTopic(id);
return new ModelAndView("home");
}
HTML: removeTopic.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org/">
<head th:replace="hello :: head">
</head>
<body class="container">
<nav th:replace="hello :: navigation"></nav>
<form th:action="#{/api/remove}" th:object="${topic}" method="post">
<div th:each="topic: ${topic}" class="checkbox">
<input type="radio" name="id" th:value="${topics.id}" th:id="${topics.id}"/>
<label th:for="${topics.id}" th:text="${topics.category}"></label>
<br/>
</div>
<input type="submit" value="Remove Topic"/>
</form>
</body>
</html>
And here is what is happeneing:
Your problem is in the loop, you are using the same object to iterate itself
th:each="topic: ${topic}"
You should have something similar to this
<div th:each="item: ${topics}" class="checkbox">
<input type="radio" name="id" th:value="${item.id}" th:id="${item.id}"/>
<label th:for="${item.id}" th:text="${item.category}"></label>
<br/> <!-- Do not use this tag to add vertical space, use css classes-->
</div>
Thanks to https://stackoverflow.com/users/2757561/cralfaro we were able to fix the connection between the controller and the removeTopic.html
The problem was is the hello.html at the
<a th:href="/removeTopic">Remove</a>
and this is how it should be:
<a th:href="#{/api/removeTopic}">Remove</a>
I'm trying to design a page using jsp-servlet which will help user to upload documents for a case / client. Here is how it should work -
Select client from a list available in option box
Based on selection - basic information about clients will be
displayed
control to upload files will be activated
User can then upload documents one by one
Save Details will save clientID and DocumentNames in MySQL
tables.
I've figured out steps #1 to #5 individually and they are working fine. Problem starts when I bring them on one page. Then I realized because my form has enctype="multipart/form-data", other values populated on form (clientID, name, etc) are not accessible in my controller in order to save Both Client and Document information in MYSQL table.
It would be great help if someone can guide me / point me to an example to follow. Thank you very much for all the help.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.cts.controller;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import com.cts.dao.CaseDocumentDAO;
import com.cts.model.CaseDocument;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class CaseDocumentController extends HttpServlet {
private static final long serialVersionUID = 1L;
private static String INSERT_OR_EDIT = "/ctsCaseDocuments.jsp";
//private static String LIST_CASEDETAIL = "/ctsListCaseDetail.jsp";
private CaseDocumentDAO dao;
private final String UPLOAD_DIRECTORY = "d:/uploads";
public CaseDocumentController() {
super();
dao = new CaseDocumentDAO();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String forward = "";
String action = request.getParameter("action");
forward = INSERT_OR_EDIT;
request.setAttribute("casemasters", dao.getAllCaseMaster());
RequestDispatcher view = request.getRequestDispatcher(forward);
view.forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
CaseDocument casedocument = new CaseDocument();
if (request.getParameter("GetDetails") != null) {
String str = request.getParameter("cad_FileName1");
System.out.println(str);
String selected_Comments[] = request.getParameterValues("cad_FileName1");
for (String comment : selected_Comments) {
System.out.println(comment);
request.setAttribute("casedetail", dao.getCaseDetailById(Integer.parseInt(comment)));
request.setAttribute("casemasters", dao.getAllCaseMaster());
request.getRequestDispatcher("/ctsCaseDocuments.jsp").forward(request, response);
}
}
if (ServletFileUpload.isMultipartContent(request)) {
try {
String fname = null;
String fsize = null;
String ftype = null;
List<FileItem> multiparts = new ServletFileUpload(
new DiskFileItemFactory()).parseRequest(request);
for (FileItem item : multiparts) {
if (!item.isFormField()) {
fname = new File(item.getName()).getName();
fsize = new Long(item.getSize()).toString();
ftype = item.getContentType();
item.write(new File(UPLOAD_DIRECTORY + File.separator
+ fname));
}
}
// File uploaded successfully
request.setAttribute("message", "File Uploaded Successfully");
request.setAttribute("name", fname);
request.setAttribute("size", fsize);
request.setAttribute("type", ftype);
} catch (Exception ex) {
request.setAttribute("message", "File Upload Failed due to "
+ ex);
}
} else {
request.setAttribute("message",
"Sorry this Servlet only handles file upload request");
}
request.getRequestDispatcher("/ctsCaseDocuments.jsp").forward(request, response);
}
}
JSP Code -
<%--
Document : ctsCasePayments
Created on : 27 May, 2016, 10:35:35 AM
Author : Admin
--%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%# page import="java.io.*,java.util.*,java.sql.*"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Upload Case Documents</title>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/sb-admin.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
<link rel="stylesheet" href="css/prism.css">
<link rel="stylesheet" href="css/chosen.css">
<style type="text/css" media="all">
/* fix rtl for demo */
.chosen-rtl .chosen-drop { left: -9000px; }
</style>
<script src="/js/jquery.validate.js"></script>
<script>
$.validator.setDefaults({
submitHandler: function () {
alert("submitted!");
}
});
});</script>
<style>
div.dataTables_wrapper {
width: 1100px;
margin: 0 auto;
}
</style>
<style>
#leftContainer {
float:left;
}
#rightContainer {
float:none;
}
</style>
</head>
<body>
<div id="wrapper">
<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">SB Admin</a>
</div>
<!-- Top Menu Items -->
<ul class="nav navbar-right top-nav">
<li class="dropdown">
<i class="fa fa-user"></i> <%=session.getAttribute("name")%> <b class="caret"></b>
<ul class="dropdown-menu">
<li>
<i class="fa fa-fw fa-user"></i> Profile
</li>
<li>
<i class="fa fa-fw fa-envelope"></i> Inbox
</li>
<li>
<i class="fa fa-fw fa-gear"></i> Settings
</li>
<li class="divider"></li>
<li>
<i class="fa fa-fw fa-power-off"></i> Log Out
</li>
</ul>
</li>
</ul>
<!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav side-nav">
<li class="active">
<i class="fa fa-fw fa-dashboard"></i> Dashboard
</li>
<li>
<i class="fa fa-fw fa-arrows-v"></i> Home <i class="fa fa-fw fa-caret-down"></i>
<ul id="demo" class="collapse">
<li>
Dashboard
</li>
<li>
ARCIL Dashboard
</li>
</ul>
</li>
<li>
<i class="fa fa-fw fa-arrows-v"></i> Operations <i class="fa fa-fw fa-caret-down"></i>
<ul id="demo1" class="collapse">
<li>
Advocates
</li>
<li>
Users
</li>
<li>
Clients
</li>
<li>
Courts
</li>
<li>
Registrar
</li>
<li>
Case Category
</li>
<li>
Case Stage
</li>
<li>
Documents
</li>
</ul>
</li>
<li>
<i class="fa fa-fw fa-arrows-v"></i> Case <i class="fa fa-fw fa-caret-down"></i>
<ul id="demo2" class="collapse">
<li>
Case Diary
</li>
<li>
Case Documents
</li>
<li>
Notice Information
</li>
<li>
Allocate Cases
</li>
<li>
Payments
</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</nav>
<div id="page-wrapper">
<div class="container-fluid">
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">
Maintain Case Expenses
</h1>
<ol class="breadcrumb">
<li>
<i class="fa fa-dashboard"></i> Dashboard
</li>
<li class="active">
<i class="fa fa-edit"></i> Maintain Case Expenses
</li>
</ol>
</div>
</div>
<!-- /.row -->
<div class="row">
<div class="col-lg-6">
<%-- <form role="form" method="POST" class="register" action='CaseExpensesController' name="frmAddCaseDetail" onsubmit="return ValidateEndDate(this)">--%>
<form role="form" method="POST" class="register" action='CaseDocumentController' name="frmUploadDocuments" >
<div class="form-group">
<p>
<table>
<tr>
<td>
<select data-placeholder="Select Case..." name ="cad_FileName1" class="chosen-select" style="width:450px;" >
<c:forEach items="${casemasters}" var="casemaster">
<option value="${casemaster.cad_ID}" ${casedetail.cad_ID == casemaster.cad_ID ? 'selected' : ''}>${casemaster.cad_CaseNo} || ${casemaster.cad_FileName}</option>
</c:forEach>
</select>
</td>
<td> <lable> </lable> </td>
<td><button type="submit" name="GetDetails" value="GetDetails" class="btn btn-primary">Get Details</button> </td>
<td> <lable> </lable> </td>
<td><button type="submit" name="AddCase" value="AddCase" class="btn btn-primary">New Case</button> </td>
</tr>
</table>
</p>
<div class="form-group">
<p>
<table>
<tr>
<td><input type="text" readonly="readonly" style="width:200px;" class="form-control" placeholder="Case ID" name="cad_id" value="<c:out value="${casedetail.cad_ID}" />" /> </td>
<td> <lable> </lable> </td>
<td><input type="text" readonly="readonly" style="width:220px;" class="form-control" placeholder="Registration No" name="cad_RegNo" value="<c:out value="${casedetail.cad_RegNo}" />" /> </td>
<td> <lable> </lable> </td>
<td><input type="text" readonly="readonly" style="width:250px;" class="form-control" placeholder="Case Number" name="cad_CaseNo" value="<c:out value="${casedetail.cad_CaseNo}" />" /> </td>
<td> <lable> </lable> </td>
<td><input type="text" readonly="readonly" style="width:250px;" class="form-control" placeholder="File Number" name="cad_FileNo" value="<c:out value="${casedetail.cad_FileNo}" />" /> </td>
</tr>
</table>
</p>
<p>
<table>
<tr>
<td><input type="text" readonly="readonly" style="width:475px;" class="form-control" placeholder="File Name" name="cad_FileName" value="<c:out value="${casedetail.cad_FileName}" />" /> </td>
<td> <lable> </lable> </td>
<td><input type="text" readonly="readonly" style="width:475px;" class="form-control" placeholder="Client Name" name="cad_ClientName" value="<c:out value="${casedetail.cad_ClientName}" />" /> </td>
</tr>
</table>
</p>
<input type="hidden" readonly="readonly" style="width:200px;" class="form-control" placeholder="CaseExpenseID" name="cce_ID" value="<c:out value="${caseexpense.cce_ID}" />" />
<input type="hidden" readonly="readonly" style="width:200px;" class="form-control" placeholder="Case ID" name="pcad_ID" value="<c:out value="${caseexpense.cad_ID}" />" />
<input type="hidden" class="form-control" name="cce_DeleteFlag" value="<c:out value="0"/>" />
<input type="hidden" class="form-control" name="cce_ActiveFlag" value="<c:out value="true" />" />
<input type="hidden" class="form-control" name="cce_CreateDate" value="<fmt:formatDate pattern="dd/MM/yyyy" value="<%= new java.util.Date()%>" />" />
<input type="hidden" class="form-control" name="cce_CreateUser" value="<c:out value="1" />" />
<input type="hidden" class="form-control" name="cce_ModifyDate" value="<fmt:formatDate pattern="dd/MM/yyyy" value="<%= new java.util.Date()%>" />" />
<input type="hidden" class="form-control" name="cce_ModifyUser" value="<c:out value="1" />" />
<p>
<%--<button type="submit" name="SaveDetails" value="SaveDetails" class="btn btn-primary" onClick="return ValidateEndDate();">Submit</button> --%>
<button type="submit" name="SaveDetails" value="SaveDetails" class="btn btn-primary" >Submit</button>
<button type="reset" class="btn btn-default">Reset Button</button>
</p>
</div>
</div>
<script type="text/javascript">
function ValidateEndDate() {
var StartDate = document.getElementById('ccd_PreviousDate').value;
var EndDate = document.getElementById('ccd_CurrentDate').value;
var tmpStartDate = StartDate.split("/");
var tmpEndDate = EndDate.split("/");
var eDate = new Date(tmpEndDate[1] + '/' + tmpEndDate[0] + '/' + tmpEndDate[2]);
var sDate = new Date(tmpStartDate[1] + '/' + tmpStartDate[0] + '/' + tmpStartDate[2]);
if (StartDate != '' && StartDate != '' && sDate.getTime() > eDate.getTime()) {
document.getElementById('NextDateError').innerText = "Please ensure that the Next Date is greater than Previous Date"
return false;
}
else
return true;
}
</script>
<script type="text/javascript">
Toggle();
function Toggle() {
if (document.frmAddCaseDetail.cboxToggle.checked) {
return ValidateEndDate();
}
}
</script>
<script>
function ctsOpenCaseStaePopUp() {
window.open("ctsCaseStage.jsp", null, "height=438, width=600, status=yes, toolbar=no, menubar=no, location=no");
}
</script>
<script>
function ctsOpenCourtPopUp() {
window.open("ctsCourtRegistration.jsp", null, "height=480, width=600, status=yes, toolbar=no, menubar=no, location=no");
}
</script>
</form>
<form method="post" action="CaseDocumentController" enctype="multipart/form-data">
Choose a file : <input type="file" name="file"> <input
type="submit" value="upload">
<div id="result">
<h3>${requestScope["message"]}</h3>
<br>
</div>
File name : ${requestScope["name"]}
<br> File size : ${requestScope["size"]}
<br> File type : ${requestScope["type"]}
</form>
</div>
</div>
<!-- /.row -->
</div>
<!-- /.container-fluid -->
</div>
<!-- /#page-wrapper -->
<!-- /#wrapper -->
<!-- jQuery -->
<script src="js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<script src="js/chosen.jquery.js" type="text/javascript"></script>
<script src="js/prism.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
var config = {
'.chosen-select': {},
'.chosen-select-deselect': {allow_single_deselect: true},
'.chosen-select-no-single': {disable_search_threshold: 10},
'.chosen-select-no-results': {no_results_text: 'Oops, nothing found!'},
'.chosen-select-width': {width: "95%"}
}
for (var selector in config) {
$(selector).chosen(config[selector]);
}
</script>
</body>
I have the following query in my model(Supplier) class :
#NamedQuery(name = "Supplier.findSupplierKeyId", query = "SELECT s FROM Supplier s WHERE s.supplierid LIKE (':supplieridkey%')")
I have following function in my Controller(SupplierSerivce) class:
public List<Supplier> findSupplierKeyId(String supplierkeyid){
List<Supplier> supplierList = mgr.createNamedQuery("Supplier.findSupplierKeyId").setParameter("supplieridkey", supplierkeyid).getResultList();
return supplierList;
}
I want to get in a html textfield :
<form action="SearchSupplierIdKey.jsp" method="POST">
<div>
<input type="text" name="supIdKey"/>
<input type="submit" value="Search" name="button"/>
</div>
</form>
then get parameter from the textfield and pass it into supService.findSupplierKeyId through servlet:
public class SearchSupplierIdKey extends HttpServlet {
#PersistenceContext
EntityManager em;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
SupplierService supService = new SupplierService(em);
HttpSession session = request.getSession();
String supId = (String) session.getAttribute("supId");
String button = (String) session.getAttribute("button");
List<Supplier> supplierListResult = supService.findSupplierKeyId(supId);
session.setAttribute("supplierListResult", supplierListResult);
if (button.equals("Search")) {
response.sendRedirect("ViewSupplierByIdKey.jsp");
}
} catch (Exception ex) {
Logger.getLogger(AddSupplier.class.getName()).log(Level.SEVERE, null, ex);
}
}
Then show the result in ViewSupplierByIdKey.jsp :
<%#page import="java.util.List"%>
<%#page import="model.Supplier"%>
<!-- retrieve session object, itemList -->
<%
List<Supplier> supplierListResult = (List)session.getAttribute("supplierListResult");
%>
<html>
<head>
<title>Supplier Search Result</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<table cellspacing="0" cellpadding="0" style="margin-left:auto; margin-right:auto; border:solid; width: 1000px">
<tr style="border:solid">
<td style="border:solid ">
<h3 style="text-align: center">ABC Health Supplement Shop System</h3>
</td>
</tr>
<tr style="border: solid">
<td style="border: solid">
<center><h1><i><b><font face="Segoe Script" color="#FF0000">Supplier Search Result(By ID Key)</font></b></i></h1></center>
</td>
</tr>
<tr style="border:solid">
<td style="border:solid">
<center><div>
<table border="1">
<tr>
<th>Supplier ID</th>
<th>Supplier Name</th>
<th>Manufacturer</th>
<th>Contact Num</th>
<th>Address</th>
</tr>
<% for (Supplier supplier: supplierListResult){ %>
<tr>
<td><%= supplier.getSupplierid() %></td>
<td><%= supplier.getSuppliername()%> </td>
<td><%= supplier.getManufacturer()%> </td>
<td><%= supplier.getContactnum()%> </td>
<td><%= supplier.getAddress()%> </td>
</tr>
<% } %>
</table>
<br><br>
<p>Back to Menu page</p>
</div>
</center>
</td>
</tr>
</table>
</body>
</html>
but i dont knw why i cant proceed to ViewSupplierByIdKey.jsp, it stuck at the controller class
(SearchSupplierIdKey.java). Please Help :( :(
One thing that I notice is the request parameter is retrieved using the name supId:
String supId = (String) session.getAttribute("supId");
but specified as supIdKey in the HTML:
<input type="text" name="supIdKey"/>
The name attribute used on the input should match the key being used to retrieve the attribute.
How to apply css and elemental styles to a ASP.net MVC 3 Web Application.here am posting my current project view code to Explain my problem.
#{
ViewBag.Title = "FranchIndex";
Layout = "~/Views/Shared/_LayoutMaster.cshtml";
}
<h2>FranchIndex</h2>
<div class="login-wrap">
<div class="login-head">
<h3>Franchise Login</h3>
</div>
<form action="#" method="get">
<div class="login-form">
<ul>
<li><i class="icon-user"></i><input type="text" class="login-user-input" #Html.TextBoxFor(Model => Model.UserName)></li>
<li><i class="icon-key"></i><input type="password" class="login-pass-input" #Html.TextBoxFor(Model=>Model.Password)></li>
</ul>
</div>
<div class="login-action">
<button type="submit" class="backend-login-btn btn btn-block btn-large btn-inverse">Login</button>
<ul class="login-initial clearfix">
<li class="pull-left">Forgot Password?</li>
<li class="pull-right"><span class="rem-check"><input type="checkbox" checked></span>Remember Me</li>
</ul>
</div>
</form>
#*<h5>If You are a Franchise,Please #Html.ActionLink("Login Here", "FranchIndex", "Login") </h5> *#
</div>
in _LayoutMaster.cshtml include:
#Styles.Render("~/Content/common")
and in App_Start/bundleConfig.css
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
// Shared Styling
bundles.Add(new StyleBundle("~/Content/common").Include(
"~/Css/Common.css",
"~/Css/jqueryui.css",
"~/Css/chosen.css"
));
}
}
or whatever combination of your individual style CSS files you have.
finally in global.asax:
protected void Application_Start()
{
BundleConfig.RegisterBundles(BundleTable.Bundles);
}