Why no files found using file uploading in Struts 2 - java

I am using org.apache.commons.*, org.apache.commons.disk.*, org.apache.commons.fileupload.servlet.* packages for file uploading in JSP program and there was no need of Struts and it was working great, data easily worked with this, but when I added Struts 2 core libraries into my web project using MyEclipse 8.5 it is not working and have no fields found. May be the program is with upload.parseRequest.
Frankly, I am unable to understand the problem, so I share my program too
AddCategory.jsp:
<html>
<head>
<meta http-equiv="refresh" content="30">
</head>
<script type="text/javascript">
function blank() {
if (document.cate.cat.value == "Enter New Category") {
alert(" Category must not be blanked !!!");
document.cate.cat.focus();
return false;
}
else if (!document.getElementById("file1").value) {
alert("No file selected");
return false;
}
else {
return true;
}
}
</script>
<form name="cate" action="CategoryAdded.jsp" method="post" enctype="multipart/form-data" onsubmit="return blank()">
<table width="100%" border="0">
<tr>
<th colspan="2" scope="col">
<div align="center">Create New Category</div>
</th>
</tr>
<tr>
<td width="50%">
<div align="right">Enter New Category:</div>
</td>
<td width="50%">
<input name="cat" type="text" id="cat" value="Enter New Category"
onFocus="if(this.value== 'Enter New Category'){ this.value='' ; this.style.background='white';}"
onBlur="if(this.value==''){this.value='Enter New Category'; this.style.background='lightyellow'}">
</td>
</tr>
<tr>
<td width="50%">
<div align="right">Upload photo:</div>
</td>
<td width="50%"><input name="file1" type="file" id="file1"></td>
</tr>
<tr>
<td colspan="2">
<div align="center">
<input type="submit" name="Submit" value="Add Category">
</div>
</td>
</tr>
</table>
</form>
</html>
CategoryAdded.jsp:
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>
<%#page import="java.io.*" %>
<%# page language="java" errorPage="" %>
<%# page import="java.sql.*" %>
<%# page import="org.apache.commons.io.*" %>
<%#page import="java.util.Iterator,java.util.List" %>
<%#page import="org.apache.commons.*,org.apache.commons.fileupload.disk.*,org.apache.commons.fileupload.servlet.*" %>
<%# page import="java.util.*" %>
<%#page import="org.apache.commons.fileupload.FileItemFactory" %>
<%#page import="org.apache.commons.fileupload.FileItem" %>
<%#page import="org.apache.commons.fileupload.FileUploadException" %>
<%#page import="p1.DBInfo" %>
<%#page import="p1.Identy" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<%
String pname = "";
Identy id = new Identy();
String cod = id.code();
boolean isMultipartContent = ServletFileUpload.isMultipartContent(request);
if (!isMultipartContent) {
System.out.println("No multipart found");
return;
}
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
try {
List<FileItem> fields = upload.parseRequest(request);
Iterator<FileItem> it = fields.iterator();
if (!it.hasNext()) {
System.out.println("No fields found");
return;
}
DBInfo obj = new DBInfo();
Connection cn = obj.getConn();
PreparedStatement ps = cn.prepareStatement("insert into category values(?,?,?)");
while (it.hasNext()) {
FileItem fileItem = it.next();
if (fileItem.getFieldName().equals("cat")) {
pname = fileItem.getString();
System.out.println("category name is " + pname);
}
boolean isFormField = fileItem.isFormField();
if (!isFormField) {
String s = fileItem.getName().substring(fileItem.getName().lastIndexOf("\\") + 1);
fileItem.write(new File("D:\\Practice\\ShoppingCart\\WebRoot\\images\\" + s));
System.out.println(s);
fileItem.getOutputStream().close();
ps.setString(3, "D:\\Practice\\ShoppingCart\\WebRoot\\images\\" + s);
}
}
ps.setString(1, pname);
ps.setString(2, pname + cod);
int i = ps.executeUpdate();
if (i == 1) {
%>
<head>
<script type="text/javascript">
function myFunction() {
var r = confirm("New Category Added Successfully!!!\nIf you Want to Add more New Category then Press Ok!!!");
if (r == true) {
window.location = "AddCategory.jsp";
}
else {
window.location = "Tryy.jsp";
}
}
</script>
</head>
<body onload="myFunction()">
</body>
<%
}
cn.close();
} catch (Exception e) {
e.printStackTrace();
}
%>
</html>

The best thing is to rewrite the JSPs to remove scriptlets and move business logic to the action classes.
You could also use Struts2 <s:if> and <s:else> tags to render content conditionally.
The commons-fileUpload is the default implementation for uploading files in Struts2, to use it correctly you could run an example Struts2 project like struts-2-upload-multiple-files-example.

Related

JSP JSTL does not write HTML

I have an assignment for a one web page to show a table based on a selected date range (week, month or quarter) and a selected date. The data is from a read-only JSON file. A <select> control is filled with start dates using jQuery (not my preference but it works). Selecting a start date should cause a set of records to be chosen to be displayed in the <table> using JSTL <c:out>. I observe the correct data being requested by <c:forEach> from EventInfo#getDate() but no HTML code is written. I also failed to get JSTL to write <option> for the <select> control or even a <label>.
I am not sure what else to check to get this to work, such as pom.xml, file locations.
The java servlet and class files are in src/edjusterJsp/.
HomePage.jsp and actions.js are in WebContent/.
The data files is in WebContent/WEB-INF/.
Development is done in Eclipse/Luna on Windows Vista using Chrome to view.
HomePage.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Joe Brown's Assignment for e|djuster</title>
<style>
.picklab
{
width: 10em;
}
.pickcontrol
{
width: 8em;
}
</style>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="actions.js"></script>
</head>
<body>
<h1>Joe Brown's Data Viewer</h1>
<c:set var="greeting" value="Hello World" />
<c:out value="${greeting}" />
<form action="JoeabServlet" method="post">
<label class="picklab">Period</label>
<select id="periodtype" class="pickcontrol pickler" required>
<option>select</option>
<option value="ptweek">Week</option>
<option value="ptmonth">Month</option>
<option value="ptquarter">Quarter</option>
</select><br>
<label class="picklab">Start Date</label>
<select id="periodrange" class="pickcontrol pickled">
<option>Please select parent</option>
</select><br>
<input type="submit" value="Update Summary" />
<table id="summaryz">
<thead>
<tr>
<th>Date</th>
<th>Type</th>
<th>Summary</th>
<th>Metric</th>
</tr>
</thead>
<tbody>
<tr>
<td>One</td>
<td>Two</td>
<td>Three</td>
<td>Four</td>
</tr>
<c:forEach items="${eventinfos}" var="evinfo">
<tr>
<td><c:out value="${evinfo.getEventDate()}" /></td>
<td><c:out value="${evinfo.getEventType()}" /></td>
<td><c:out value="${evinfo.getEventSummary()}" /></td>
<td><c:out value="${evinfo.getEventSize()}" /></td>
</tr>
</c:forEach>
</tbody>
</table>
</form>
</body>
</html>
JoeabServlet.java (portion)
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
String fillid = request.getParameter("fillid"); // ID of child DD to fill options for.
String periodsize = request.getParameter("periodsize");
String val = request.getParameter("val"); // Value of parent DD to find associated child DD options for.
System.out.println("doGet() fillid: " + fillid + " periodsize: " + periodsize + " val: " + val);
String jsonText = "invalid";
if (0 == fillid.compareTo("periodrange"))
{
// Generate date options for a period type
List<String> dates = getPeriodRanges(val);
StringWriter sw = new StringWriter();
JSONValue.writeJSONString(dates, sw);
jsonText = sw.toString();
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(jsonText);
}
else if (0 == fillid.compareTo("summaryz"))
{
// Generate summary data for the table
System.out.println("doGet() matched summaryz");
List<EventInfo> evInfos = getEventInfos(periodsize, val);
request.setAttribute("eventinfos", evInfos);
request.getRequestDispatcher("/HomePage.jsp").forward(request, response);
}
}
actions.js (portion)
function fillSummaries(tableToFillID, ddTypeId, callingElement)
{
var tableau = $("#" + tableToFillID);
var dd = $('#' + ddTypeId);
console.debug("selected: " + $(callingElement).children(':selected'));
console.debug("selected text: " + $(callingElement).children(':selected').text());
sdate = $(callingElement).children(':selected').text();
console.debug("sdate : " + sdate);
$.getJSON('http://localhost:8080/edjusterJsp/JoeabServlet?fillid=' + tableToFillID + '&periodsize=' + dd.val() + '&val=' + sdate);
}
EventInfo.java (portion)
public class EventInfo
{
protected String event_date;
protected String event_type;
protected String event_summary;
protected String event_size;
public String getEventDate()
{
System.out.println("get event_date" + event_date);
return event_date;
}
}

Integrating Eclipse with MySQL

I am facing a problem while integrating a web application developed in eclipse with a mysql database (mysql workbench).
below are the jsp files I used and the database name.
database username -- root
password -- 1234
Login.jsp
<%--
Document : Login
Created on : 28 Feb, 2015, 8:50:26 AM
Author : Lahaul Seth
--%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Login Demo with JSP</title>
</head>
<body>
<form method="post" action="userdetail.jsp">
<center>
<table border="1" cellpadding="5" cellspacing="2">
<thead>
<tr>
<th colspan="2">Login Here</th>
</tr>
</thead>
<tbody>
<tr>
<td>Username</td>
<td><input type="text" name="username" required/></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" required/></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Login" />
<input type="reset" value="Reset" />
</td>
</tr>
</tbody>
</table>
</center>
</form>
</body>
</html>
userdetail.jsp
<%# page language="java" %>
<%# page import="org.owasp.esapi.ESAPI" %>
<%# page import="org.owasp.esapi.codecs.Codec" %>
<%# page import="org.owasp.esapi.codecs.MySQLCodec" %>
<%# page import="java.sql.*" %>
<%# page import="java.io.*" %>
<%! Connection con= null; %>
<%! Statement stmt= null; %>
<%! ResultSet rs= null; %>
<%! MySQLCodec mc= null; %>
<html>
<head><title>List Users</title></head>
<%
String uname = request.getParameter("uname");
String pass = request.getParameter("pass");
String uid = request.getParameter("uid");
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
}catch(ClassNotFoundException ce){out.println(ce);}
try{
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "1234");
stmt = con.createStatement();
String sql = "select * from userdetail where id = "+Integer.parseInt(uid);
//out.println(sql);
rs = stmt.executeQuery(sql);
%>
<body>
<br>
<br>
<div align="center"><b>You have Successfully Logged In Mr/Ms<%=uname%>, Your Details are :-</b></div>
<br>
<br>
<br>
<form action="view.jsp">
<table align="center">
<% while(rs.next()) {%>
<tr><td>First Name</td><td><input type=text name="fname" value='<%=rs.getString("firstname")%>' ></td></tr>
<tr><td>Last Name</td><td><input type=text name="lname" value='<%=rs.getString("lastname")%>'></td></tr>
<tr><td>Email</td><td><input type=text name="email" value='<%=rs.getString("email")%>'></td></tr>
<tr><td>Phone</td><td><input type=text name="phone" value='<%=rs.getString("phone")%>'></td></tr>
<tr><td>Address</td><td><input type=text name="address" value='<%=rs.getString("address")%>'></td></tr>
<%
}
rs.close();
stmt.close();
con.close();
}catch(SQLException exception){
//out.println("<!--");
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
exception.printStackTrace(pw);
out.print(sw);
sw.close();
pw.close();
//out.println("-->");
}
%>
</table>
</form>
</body>
</html>
auth.jsp
<%# page language="java" %>
<%# page import="org.owasp.esapi.ESAPI" %>
<%# page import="org.owasp.esapi.codecs.Codec" %>
<%# page import="org.owasp.esapi.codecs.MySQLCodec" %>
<%# page import="java.sql.*" %>
<%# page import="java.io.*" %>
<%! Connection con=null; %>
<%! Statement stmt= null; %>
<%! ResultSet rs= null; %>
<%! MySQLCodec mc= null; %>
<html>
<head><title>This is a Jdbc Example</title></head>
<body>
<%
String uname = request.getParameter("uname");
String pass = request.getParameter("pass");
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
}catch(ClassNotFoundException ce){out.println(ce);}
try{
con = DriverManager.getConnection("jdbc:mysql://localhost/test:3306","root", "1234");
stmt = con.createStatement();
//String sql = "select * from user_detail where uname='" + uname +"' and pass='" + pass + "'";
mc = new MySQLCodec(0);
String sql = "SELECT * FROM userdetail WHERE uname = '" + ESAPI.encoder().encodeForSQL( mc, uname) + "' and pass = '" + ESAPI.encoder().encodeForSQL( mc, pass) +"'";
out.println(sql);
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
if (rs.next()) {
boolean loggedIn = true;
//response.sendRedirect("userdetail.jsp?uid=1");
out.println("Successfully logged in");
} else {
//response.sendRedirect("login.jsp");
out.println("Username and/or password not recognized");
}
rs.close();
stmt.close();
con.close();
}catch(SQLException exception){
//out.println("<!--");
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
exception.printStackTrace(pw);
out.print(sw);
sw.close();
pw.close();
//out.println("-->");
}
%>
</body>
</html>
MySQL datatbase
Error page
Well, this sounds to be a class path issue. Could you please check MySQLCodec class present in WEB-INF/classes or present in any jar in WEB-INF/lib path.
You can double check the tomcat war directory. It should be in the below sample folder structure.

sql statement not working in jsp

This is the Code i have , I think its the Sql string that is not working correctly. im able to view the table and cick on the edit field but im only able to update the first row. i want to be able to select a row and than edit it according to its id .
//Database View
<%# page import="java.sql.ResultSet" %>
<%# page import="java.sql.SQLException" %>
<%# page import="java.sql.Statement" %>
<%# page import="java.sql.Connection" %>
<%# page import="java.sql.DriverManager" %>
<html>
<head>
<title>Inventory</title>
</head>
<body>
<%
Connection connect = null;
Statement s = null;
try {
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection("jdbc:mysql://localhost/client", "rootroot", "rootroot");
s = connect.createStatement();
String sql = "SELECT * FROM client ORDER BY id ASC";
ResultSet rec = s.executeQuery(sql);
%>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">id </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="59"> <div align="center">Budget </div></th>
<th width="71"> <div align="center">Edit </div></th>
</tr>
<%while((rec!=null) && (rec.next())) { %>
<tr>
<td><div align="center"><%=rec.getString("id")%></div></td>
<td><%=rec.getString("first_name")%></td>
<td><%=rec.getString("last_name")%></td>
<td><div align="center"><%=rec.getString("blood_type")%></div></td>
<td align="right"><%=rec.getString("gender")%></td>
<td align="center"> Edit</td>
</tr>
<%}%>
</table>
<%
} catch (Exception e) {
// TODO Auto-generated catch block
out.println(e.getMessage());
e.printStackTrace();
}
try {
if(s!=null){
s.close();
connect.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
out.println(e.getMessage());
e.printStackTrace();
}
%>
</body>
</html>
//Edit Page
<%# page import="java.sql.ResultSet" %>
<%# page import="java.sql.SQLException" %>
<%# page import="java.sql.Statement" %>
<%# page import="java.sql.Connection" %>
<%# page import="java.sql.DriverManager" %>
<html>
<head>
<title>ThaiCreate.Com JSP Tutorial</title>
</head>
<body>
<%
Connection connect = null;
Statement s = null;
try {
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection("jdbc:mysql://localhost/client", "rootroot", "rootroot");
s = connect.createStatement();
String sql ="SELECT * FROM client";
ResultSet rec = s.executeQuery(sql);
if(rec != null) {
rec.next();
%>
<form name="frmUpdate" method="post" action="SaveEdit.jsp?id=<%=rec.getString("id")%>">
Update Form
<table width="428" border="1">
<tr>
<th width="181">
<div align="left">Product ID </div></th>
<td width="231"><%=rec.getString("id")%></td>
</tr>
<tr>
<th width="181">
<div align="left">Name </div></th>
<td><input type="text" name="txtName" size="20" value="<%=rec.getString("first_name")%>"></td>
</tr>
<tr>
<th width="181">
<div align="left">Email </div></th>
<td><input type="text" name="txtEmail" size="20" value="<%=rec.getString("last_name")%>"></td>
</tr>
<tr>
<th width="181">
<div align="left">CountryCode </div></th>
<td><input type="text" name="txtCountryCode" size="2" value="<%=rec.getString("blood_type")%>"></td>
</tr>
<tr>
<th width="181">
<div align="left">Budget </div></th>
<td><input type="text" name="txtBudget" size="5" value="<%=rec.getString("gender")%>"></td>
</tr>
</table>
<input type="submit" value="Save">
</form>
<% }
} catch (Exception e) {
// TODO Auto-generated catch block
out.println(e.getMessage());
e.printStackTrace();
}
try {
if(s!=null){
s.close();
connect.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
out.println(e.getMessage());
e.printStackTrace();
}
%>
</body>
</html>
// save page
<%# page import="java.sql.ResultSet" %>
<%# page import="java.sql.SQLException" %>
<%# page import="java.sql.Statement" %>
<%# page import="java.sql.Connection" %>
<%# page import="java.sql.DriverManager" %>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<%
Connection connect = null;
Statement s = null;
try {
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection("jdbc:mysql://localhost/client", "rootroot", "rootroot");
s = connect.createStatement();
String strCustomerID = request.getParameter("id");
String strName = request.getParameter("txtName");
String strEmail = request.getParameter("txtEmail");
String strCountryCode = request.getParameter("txtCountryCode");
String strBudget = request.getParameter("txtBudget");
String sql = "UPDATE client " +
"SET first_name = '"+ strName + "' " +
", last_name = '"+ strEmail + "' " +
", blood_type = '"+ strCountryCode + "' " +
", gender = '"+ strBudget + "' " +
" WHERE id = '" + strCustomerID + "' ";
s.execute(sql);
out.println("Record Update Successfully");
} catch (Exception e) {
// TODO Auto-generated catch block
out.println(e.getMessage());
e.printStackTrace();
}
try {
if(s!=null){
s.close();
connect.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
out.println(e.getMessage());
e.printStackTrace();
}
%>
</body>
</html>
please try s.executeUpdate(sql); instead of s.execute(sql);
First of all +1 for what Elliott Frisch says. Such spaghetti code is very bad practice.
Anyway, if I understand correctly your use case, then you need to obtain at the Edit page the id parameter from URL/request and add into the select appropriate condition so it looks something like
"SELECT * FROM client WHERE id = '" + clientId + "' "
If you don't put the condition in there, it will always return whole table and based on your code you're just taking the first row and ignoring the rest. Which is very inefficient way to work with DB.
Another thing you should consider are binds and something what is called preparedStatement - try to google it and learn something about it. The main reason to use it is to avoid SQL injection using which somebody can easily mess up or compromise your database data.
I personally would also replace * by listing of all columns which you really need.

JAVA String error in JSP

Im getting a curious error with an ArrayList, below is the code (note that this code was copied from an online servlet example, I am a JAVA novice).
the JSP:
<%#page import="p.SecondExample"%>
<%# page language="java" import="java.util.*;"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Servlet Application</TITLE>
<script language="javascript">
function editRecord(id){
window.location.href="editServlet/"+id;
}
function deleteRecord(id){
window.location.href="deleteUser/"+id;
}
</script>
</HEAD>
<BODY>
<br>
<table align="center">
</table>
<br>
<table width="600px" align="center" style="background-color:#EDF6EA;border:1px solid #000000;">
<tr><td colspan=9 align="center" height="10px"></td></tr>
<tr><td colspan=9 align="center"><!-- Add New User--></td></tr>
<tr><td colspan=9 align="center" height="10px"></td></tr>
<tr style="background-color:#7BA88B;font-weight:bold;">
<td>Sector Segment</td><td>Color</td>
</tr>
<%
String bgcolor="";
int count=0;
List viewList = new ArrayList();
Iterator viewItr;
SecondExample se = new SecondExample();
se.doPost(request, response);
if(request.getAttribute("userList")!=null && request.getAttribute("userList")!="")
{
List userList = (ArrayList)request.getAttribute("userList");
Iterator itr = userList.iterator();
System.out.println(userList);
while(itr.hasNext())
{
if(count%2==0)
{
bgcolor = "#C8E2D1";
}
else
{
bgcolor = "#EAF8EF";
}
viewList = (ArrayList)itr.next();
int id = Integer.parseInt(viewList.get(0).toString());
viewItr = viewList.iterator();
%>
<tr style="background-color:<%=bgcolor%>;">
<%
while(viewItr.hasNext())
{
%>
<td><%=viewItr.next()%></td>
<%
}
count++;
%>
<td><input type="button" name="edit" value="Edit" style="background-color:#49743D;font-weight:bold;color:#ffffff;" onclick="editRecord(<%=id%>);" ></td>
<td><input type="button" name="delete" style="background-color:#ff0000;font-weight:bold;;color:#ffffff;" value="Delete" onclick="deleteRecord(<%=id%>);"></td>
</tr>
<%
}
}
if(count==0)
{
%>
<tr><td colspan="9" align="center"> </td></tr>
<tr><td colspan="9" align="center">No Record Avaliable</td></tr>
<%
}
%>
<tr><td colspan=9 align="center" height="2px"></td></tr>
</table>
</BODY>
</HTML>
in debug, the error appears to occur with:
viewList = (ArrayList)itr.next();
int id = Integer.parseInt(viewList.get(0).toString());
viewItr = viewList.iterator();
where my error appears as:
org.apache.jasper.JasperException: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.ArrayList
I'm not quite sure why or how to make next a string. Any help is greatly appreciated.
Yep, itr.next() returns a String, which cannot be cast into an ArrayList.
String value = (String) itr.next();
int id = Integer.parseInt(value);
The following few lines of code in which you're iterating over your viewArray can be removed now, too.

Why is my exception about pagecontext which I do not have?

I get this error message
pageContext cannot be resolved
but I have no variable pagecontext.
This is the code (I know there are other problems here that are beyond the scope of this question):
<%#page import="se.prv.pandora.arendeprocess.util.PandoraPersonHandler"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%# taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%# page import="org.apache.log4j.Logger" %>
<%# page import="java.util.List" %>
<%# page import="java.util.ArrayList" %>
<%# page import="java.util.HashMap" %>
<%# page import="java.util.Set" %>
<%# page import="java.util.Map" %>
<%# page import="se.prv.pandora.arendeprocess.general.ArendeProcessLocator"%>
<%# page import="se.prv.pandora.arendeprocess.page.ArendeProcessPageController" %>
<%# page import="se.prv.pandora.arendeprocess.page.GrunduppgifterPageController" %>
<%# page import="se.prv.pandora.arendeprocess.obj.Navigation" %>
<%# page import="se.prv.pandora.arendeprocess.obj.AnsokanInfo" %>
<%# page import="se.prv.pandora.arendeprocess.obj.Oversikt" %>
<%# page import="se.prv.pandora.arendeprocess.obj.PersonInfo" %>
<%# page import="se.prv.pandora.arendeprocess.obj.PersonInfoIndex" %>
<%# page import="se.prv.pandora.arendeprocess.obj.Land" %>
<%# page import="se.prv.pandora.arendeprocess.obj.ArendesokInfo" %>
<%# page import="se.prv.pandora.arendeprocess.entity.Prioritet" %>
<%# page import="se.prv.pandora.arendeprocess.util.PandoraFieldConstants" %>
<%# page import="se.prv.pandora.arendeprocess.entity.Deposition" %>
<%# page import="se.prv.pandora.arendeprocess.util.ArendeComparatorManager" %>
<%# page import="se.prv.pandora.arendeprocess.obj.ArendeSearchAdmin" %>
<%# page import="se.prv.framework.forms.IFormData" %>
<%# page import="se.prv.framework.general.Action" %>
<%# page import="java.util.Iterator" %>
<%# page import="java.text.DateFormat" %>
<%# page import="java.text.SimpleDateFormat" %>
<%#page import="se.prv.pandora.arendeprocess.obj.ArendeProcessSessionData"%>
<%# page import="se.prv.pandora.arendeprocess.util.PandoraConstants" %>
<%#page import="se.prv.pandora.arendeprocess.entity.PRVNummerPerson"%>
<%# page import="se.prv.pandora.arendeprocess.entity.Region" %>
<%# page import="se.prv.pandora.arendeprocess.obj.Land" %>
<%# page import="se.prv.pandora.arendeprocess.entity.LandKod" %>
<%# page import="se.prv.pandora.arendeprocess.util.MessageHandler" %>
<%#page import="se.prv.pandora.arendeprocess.general.PandoraManager"%>
<html>
<head><link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/themes/base/jquery-ui.css">
<link href="css_js/styles.css" rel="stylesheet" type="text/css">
<link href="css_js/positions.css" rel="stylesheet" type="text/css">
<link href="css_js/dialog_box.css" rel="stylesheet" type="text/css">
<link href="css_js/floats.css" rel="stylesheet" type="text/css">
<script language="JavaScript1.2" src="css_js/jquery-1.7.1.min.js" type="text/javascript"></script>
<script language="JavaScript1.2" src="css_js/jquery-ui-1.8.17.custom.min.js" type="text/javascript"></script>
<script language="JavaScript1.2" src="css_js/sorttable.js" type="text/javascript"></script>
<script language="JavaScript1.2" src="css_js/general_arendeprocess.js" type="text/javascript"></script>
<script language="JavaScript1.2" src="css_js/dialog_box.js" type="text/javascript"></script>
<script language="JavaScript1.2" type="text/javascript">
function ingVar(x) {
var applicationDependence;
applicationDependence = x;
document.getElementById('ff').style.display='none';
document.getElementById('avd').style.display='none';
document.getElementById('utb').style.display='none';
document.getElementById('oepa').style.display='none';
document.getElementById('aooep').style.display='none';
if (applicationDependence == 'ff'){
document.getElementById('ob').style.display='none';
document.getElementById('ff').style.display='';
}
if (applicationDependence == 'avd'){
document.getElementById('ob').style.display='none';
document.getElementById('avd').style.display='';
}
if (applicationDependence == 'utb'){
document.getElementById('ob').style.display='none';
document.getElementById('utb').style.display='';
}
if (applicationDependence == 'oepa'){
document.getElementById('ob').style.display='none';
document.getElementById('oepa').style.display='';
}
if (applicationDependence == 'aooep'){
document.getElementById('ob').style.display='none';
document.getElementById('aooep').style.display='';
}
if (applicationDependence == 'ob'){
document.getElementById('ob').style.display='';
}
}
function popup() {
//alert('opening popup');
var popup = $('.newpopup');
popup.draggable();
//popup.resizable();
//popup.html('<p>Where is pancakes house?</p>');
//popup.show('fast');
//Comment me out and use the version below to show working
$.ajax({url:'/PandoraArendeWeb/popup.jsp',
error: function() {
alert('Error');
},
success: function(data) {
popup.html(data);
popup.show('fast');
}
}
);
/*
popup.html("test");
popup.show('fast');
*/
var screen_width = $(document).width();
var screen_height = $(document).height();
var box_width = popup.width();
var box_height = popup.height();
var top = (screen_height - box_height) / 2; // you might like to subtract a little to position it slightly higher than half way
var left = (screen_width - box_width) / 2;
popup.css({ 'position': 'absolute', 'top':top, 'left':left, 'overlayShow':true,'transitionIn' : 'elastic','transitionOut' : 'elastic','opacity' : '0.80' });
}
$(".newpopup").css('background-color', 'white');
$(document).ready(function(){
$('button').click(function(){
popup();
});
})
function popup2() {
alert('test');
var popup = $('.newpopup');
popup.draggable();
//popup.resizable();
//popup.html('<p>Where is pancakes house?</p>');
//popup.show('fast');
$.get('/PandoraArendeWeb/popup.jsp', function(data) {
popup.html(data);
popup.show('fast');
});
var screen_width = $(document).width();
var screen_height = $(document).height();
var box_width = popup.width();
var box_height = popup.height();
var top = (screen_height - box_height) / 2; // you might like to subtract a little to position it slightly higher than half way
var left = (screen_width - box_width) / 2;
popup.css({ 'position': 'absolute', 'top':top, 'left':left });
}
$(document).ready(function(){
$('#mypopup').click(function(){
popup();
});
})
$(document).ready(function() {
var $dialog = $('<div></div>')
.html('This dialog will show every time!')
.dialog({
autoOpen: false,
title: 'Basic Dialog'
});
$('#opener').click(function() {
$dialog.dialog('open');
// prevent the default action, e.g., following a link
$("#opener").load('PandoraArendeWeb/popup.jsp').dialog({modal:true});
return false;
});
});
</script>
<title>Ingivningsdag - NAT. - Pandora </title>
</head>
<%
final Logger logger = Logger.getLogger("arendeprocess_grunduppgifter.jsp");
ArendeProcessPageController apc = new ArendeProcessPageController(request);
GrunduppgifterPageController pc = new GrunduppgifterPageController(request);
ArendeProcessSessionData sessionData =(ArendeProcessSessionData) PandoraManager.getSessionData(request);
String arendeTyp = apc.getArendeTyp();
boolean showSearch = false;
boolean showSearchD = false;
boolean showSearchP = false;
boolean showSearchI = false;
boolean showSearchR = false;
boolean showSearch2 = false;
boolean showSearchF = false;
boolean showSearchA = false;
boolean showSearchU = false;
boolean showSearchO = false;
boolean showSearchEPa = false;
boolean showSearchEPn = false;
AnsokanInfo ansokanInfo = apc.getAnsokanInfo();
PersonInfo editPerson = new PersonInfo();
PersonInfo editOmbud = new PersonInfo();
String chosenPersonTyp = "";
String chosenPersonOrdNr = "";
if(ansokanInfo != null && ansokanInfo.hasEditPersonInfo()) {
editPerson = ansokanInfo.getEditPersonInfo();
Action latestAction = sessionData.getLatestAction();
chosenPersonTyp = latestAction.getActionModifier();
//+1 eftersom listindex börjar på 0
chosenPersonOrdNr = latestAction.getCurrIndexAsInt()+1+"";
} else {
editPerson.setFornamn(apc.getNyregPerson().getFornamn());
editPerson.setEfternamn(apc.getNyregPerson().getEfternamn());
editPerson.setForetag(apc.getNyregPerson().getForetag());
//editPerson.setOrgnr(apc.getNyregPerson().getOrgnr());
editPerson.setLandKod(apc.getNyregPerson().getLandKod());
editPerson.setReferens(apc.getNyregPerson().getReferens());
}
if(apc.getLatestAction().equals("Namnsokning") && apc.getLatestActionCommand().equals("search")) {
showSearch = true;
}
if(apc.getLatestAction().equals("Arendesokning") && apc.getLatestActionCommand().equals("search")) {
showSearchF = true;
}
int nbOfRelatedPersons = 0;
String relatedPersons = "";
if(editPerson.getPersonTyp().containsKey(PandoraConstants.PERSONTYP_OMBUD)) {
editOmbud = editPerson;
PersonInfoIndex pii = editOmbud.getPersonTyp().get(PandoraConstants.PERSONTYP_OMBUD);
if(pii!=null) {
nbOfRelatedPersons = pii.getRelatedPersons().size();
//Ska bara skrivas ut om inte ombudet gäller för alla sökande
if(ansokanInfo.getSokandeList().size()> nbOfRelatedPersons)
relatedPersons = pii.getRelatedPersonsAsString();
}
editPerson = new PersonInfo();
}
int vectr = 0; // får bara användas i errormessages.jspf
IFormData ifData = sessionData.getFormData();
%>
<body id="content" onload="if(document.getElementById('beroende') != null) { ingVar(document.getElementById('beroende').value); }">
<br><br>Sök person/<br>företag:<br>
<input type="button" value="Sök" onClick="document.getElementById('popupF').style.display='';">
<div class="popup" id="popupF"
<% if(!showSearchF) { %>
style="display: none;"
<% } %>
>
<%# include file="WEB-INF/jspf/fullfoljd_fran_sok.jspf" %>
</div></div></div>
<div class="popup" id="popupSokNamn2"
<% if(!showSearch2) { %>
style="display: none;"
<% } %>
>
<%# include file="WEB-INF/jspf/namnuppgifter_sok2.jspf" %>
</div></div></div>
<div class="popup" id="popupSokNamn"
<% if(!showSearch) { %>
style="display: none;"
<% } %>
>
<%# include file="WEB-INF/jspf/namnuppgifter_sok.jspf" %>
</div></div></div>
<div class="popup" id="popupD"
<% if(!showSearchD) { %>
style="display: none;"
<% } %>
>
<%# include file="WEB-INF/jspf/handlaggare_sok.jspf" %>
</div></div></div>
<div class="popup" id="popupI"
<% if(!showSearchI) { %>
style="display: none;"
<% } %>
>
<%# include file="WEB-INF/jspf/ingivningsdag_sok.jspf" %>
</div></div></div>
<div class="popup" id="popupP"
<% if(!showSearchP) { %>
style="display: none;"
<% } %>
>
<%# include file="WEB-INF/jspf/prioriteter_sok.jspf" %>
</div></div></div>
<div class="popup" id="popupR"
<% if(!showSearchR) { %>
style="display: none;"
<% } %>
>
<%# include file="WEB-INF/jspf/rabattgrundande_sok.jspf" %>
</div></div></div>
</form>
<%# include file="WEB-INF/jspf/arendeprocess_messages_inc.jspf" %>
<p> </p><p> </p><p> </p><p> </p>
</body>
</html>
And when I add this part it starts complaining about pagecontext:
<div class="popup" id="popupF"
<% if(!showSearchF) { %>
style="display: none;"
<% } %>
>
<%# include file="WEB-INF/jspf/fullfoljd_fran_sok.jspf" %>
</div>
I don't even have JSP code in the popup, I reduced it to plain HTML to prove that it is not my JSP that is causing this error:
<table width="100%" border="1" cellspacing="0" cellpadding="2" align="center" class="TB_nb">
<tr>
<td colspan="3" class="pusher TB_nb"><h2>Sök efter ärende</h2>
</td>
<td>X</td>
</tr>
</table>
<br><br>
<h2 class="pusher">Sök efter ärende</h2>
<div id="FVsok">
<div style="text-align: right; width: 100%; padding-right: 5%; padding-top: 5px;">
<span onClick="getElementById('FsokF').style.display='', getElementById('FbottomA').style.display='none', getElementById('FbottomV').style.display='', getElementById('FVsok').style.display='none'" class="link_sm">Visa sökformulär</span>
</div>
</div>
<div id="FsokF">
<div style="text-align: right; width: 100%; padding-right: 5%; padding-top: 5px;; padding-bottom: 5px;">
<span onClick="getElementById('FsokF').style.display='none', getElementById('FbottomA').style.display='none', getElementById('FbottomV').style.display='', getElementById('FVsok').style.display=''" class="link_sm">Dölj sökformulär</span>
</div>
<div style="width: 100%; margin-left: 15px; margin-right: 80px;" class="fontS80">
<div class="fl30"> Sök efter ärende</div><div class="clear"></div>
<div class="fl30"><input type="text" size="60" name=""></div>
<div class="clear"></div>
<div class="fl30"><input type="button" value="Avbryt"></div>
<div class="fl10"><input type="button" value=" Sök " onclick="javascript:doSubmit('Arendesokning', 'search')"></div>
<div class="clear"> </div>
</div>
</div>
<div style="width: 100%; margin-left: 15px; margin-right: 15px;">
<table width="100%" border="0" cellspacing="0" cellpadding="4" align="center">
<tr>
<td><h3>Sökresultat:</h3></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="4">En massa text <span class="link">Hjälp!</span> </td>
</tr>
<tr>
<td><input type="button" value="Visa alla"></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr class="smallb">
<td>Antal ärenden: <%= resultList.size() %></td>
<td> </td>
<td>Visa ärenden: <a class="link" href="javascript:doSubmit('MenyNavigation', 'REW_<%= thisPage %>')" >
</a>
<a class="link" href="javascript:doSubmit('MenyNavigation', 'FWD_<%= thisPage %>')" >
</a> </td>
<td> </td>
</tr>
</table>
<table width="100%" cellspacing="0" align="center" class="sortable" id="unique_id">
<tr>
<th class="thkant">Ärende</th>
<th class="thkant">Ingivningsdag</th>
<th class="thkant">Sökande1</th>
<th class="thkant">Uppfinnare1</th>
<th class="thkant">Ombud1</th><!--
<th class="thkant">Region</th>
<th class="thkant">Land</th>
<th class="thkant">Telefonnummer</th>-->
</tr>
<tr class="g2" onmouseover="javascript:setStoreStyle(this)"; onmouseout="javascript:getStoreStyle(this)" <%}else{%>class="g1" onmouseover="javascript:setStoreStyle(this)" onmouseout="javascript:getStoreStyle(this)"<%} %> onclick="javascript:goToOversikt('','','','','','')" style="cursor:pointer;">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
<div id="FbottomV">
<table width="100%" align="center">
<tr>
<td align="left"><input type="button" id="visaknapp" value="Visa" disabled style="width:150px;" onClick="getElementById('sokR').style.display='', getElementById('bottomA').style.display='', getElementById('bottomV').style.display='none', getElementById('Vsok').style.display='', getElementById('sokF').style.display='none'"></td>
<td align="right"><input type="button" value="Avbryt" style="width:150px;" class="checkmargin"><input type="button" value="Infoga" disabled style="width:150px;"></td>
</tr>
</table>
</div>
<div id="FbottomA" style="display: none">
<table width="100%" align="center">
<tr>
<td align="left"><input type="button" value="Ändra i register" style="width:150px;"></td>
<td align="right"><input type="button" value="Avbryt" style="width:150px;" class="checkmargin"><input type="button" value="Infoga" style="width:150px;"></td>
</tr>
</table>
</div>
I think this is because of having scriplets in your JSP. You might have some scriptlet which is not closing the block properly.
Or could be some of your jspf's are is not having proper braces. Look at your generated Java code and debug where it has gone wrong.
Using Java code inside JSP should be avoided to get rid of these kind of problems. Java code should be put in Sevlets and EL should be used in JSP's.

Categories

Resources