I would like to create a radio button to select the values displayed on a jsp page.
how can I use radio buttons to select values from this JSP page ?
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%! int i=0; %>
<h1 align="center">DOCUMENT INFORMATION CENTER</h1>
<table border="12" align="center">
<tr><td>Employee ID</td><td>Document ID</td><td>Topic</td><td>Text</td><td>Files</td></tr>
<% int j=(Integer)session.getAttribute("i");
HttpSession session2=request.getSession();
for(i=0;i<j;i++)
{ out.println("<tr><td>"+session.getAttribute("eid"+i)+"</td><td>"+session2.getAttribute("id"+i)+"</td><td>"+session2.getAttribute("topic"+i)+"</td><td>"+session2.getAttribute("text"+i)+"</td><td>"+session2.getAttribute("files"+i)+"</td></tr>");
}
%>
</table>
</body>
</html>
You can use struts logic tags for this purpose. If the session logic present set the value of particular radio button as true. For iterating purpose also you can use logic:iterate tag. Following piece of code may help you.
<logic:present name="i" scope="session">
<logic:equal value="1" name="i" scope="session">
<script>
$('input[name=some_name][value=1]').prop("checked",true);
</script>
</logic:equal>
</logic:present>
Let me know if this helps..
Related
I'm trying to write a simple web app in JSP that allows user to choose 2 numbers in the range 1-100 from 2 drop-down lists and then print out those numbers. However, I keep receiving the error message:
Below is my code:
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Game Table</title>
</head>
<body>
<form method="post">
#rows:
<select name="row">
<%
for(int i=1;i<=100;i++){
out.println("<option value="+"\""+i+"\""+">"+i+"</option>");
}
%>
</select>
#columns:
<select name="column">
<%
for(int i=1;i<=100;i++){
out.println("<option value="+"\""+i+"\""+">"+i+"</option>");
}
%>
</form>
<%
String row=request.getParameter("row");
String column=request.getParameter("column");
if(row!=null && column!=null){
out.println(row+" "+column);
}
%>
</body>
Thank you so much
well, problem is in navigation not in your code. For not showing dropdown menu so use proper url mapping to run your jsp like http://localhost:8080/yourwebprojectname/game.jsp game.jsp is assumption of your following above code page name.
Your code have many error like missing of action="" like
<form method="post" action="book.jsp">
</Select> tag above the form
Main problem is you dont have any button or use of ajax to show the output that you trying to display via Scriptlet
for simple solution add a button inside your form
<input type="submit" value="show" name="show"/>
add code something like this inside your Scriptlet
if("show".equals(request.getParameter("show"))){
if(row!=null && column!=null){
out.println(row+" "+column);
}
}
I am not completely sure, but it might be returning 404 (not found) because you are not submitting this data correctly. See, there is no "action" atribute indicating where it should go (e.g. "save.jsp").
Hope it helps! :)
my question is how to get the contents of a textbox in my javahttpserver webinterface
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Message - Send</title>
</head>
<body>
<input id="message" type="text"/>
<button id="message_send" type="button">Send</button>
</body>
</html>
Do I need to do it via javascript or java?
Call this function with jquery in it when the button is pushed. (I put an alert function in it so you can test it)
Make sure you include the jquery.js
function getstuff(){
var box = $("#textboxtarget").val();
alert(box);
}
I have a jsp web application, When i try to deploy it to tomcat server, and try to run the application from different machines, i dont get new pages for every user.
My application takes input from html input and keep it in the memory with the press of the button, ao actually i push the values in the memory and keeps it untill reset is pressed.
The problem comes when i goto another machine and run that application, all i get is the same modified page from that previous user.
I have used session management to keep username in the session.
But as if my application is not creating a new session for every new user request.
eg:
main.jsp has some input fields and when i click 'add' those values from html input is stored in memory objects, and is showed in the html inputs till the memory is not cleared.
Now from another machine, i access this application and go to main.jsp, there i get prefilled html input boxes.
why am i not getting a new page everytime i go from a different machine.
Is tomcat server serves all users from same memory space?
Sample code for main.jsp
<%# page import="test.DatabaseAccessConnectionManager" %>
<%# page import="test.FunctionKeywordManager" %>
<%# page import="test.TestScenarioManager" %>
<%# page import="test.DataParameter" %>
<%# page import="test.RepositoryManager" %>
<%# page import="java.util.ListIterator"%>
<%# page import="java.util.*"%>
<%# page import="java.sql.ResultSet"%>
<%# page import="test.TestCase" %>
<%# page import="test.ReportGenerator" %>
<jsp:useBean id="connn" scope="session" class="test.DatabaseAccessConnectionManager"></jsp:useBean>
<jsp:useBean id="connn1" scope="session" class="test.FunctionKeywordManager"></jsp:useBean>
<jsp:useBean id="connn2" scope="session" class="test.TestScenarioManager"></jsp:useBean>
<%
String Username=null;
String projectName = null;
if(session.getAttribute("Username")!=null)
{
Username = session.getAttribute("Username").toString();
projectName = session.getAttribute("ProjectName").toString();
}
else
{
response.sendRedirect("Login.jsp");
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Test Scenario Management</title>
<script src="static/js/jquery-2.1.3.min.js"></script>
<script src="static/js/script.js"></script>
<link rel="stylesheet" type="text/css" href="static/css/style.css">
<!-- <script>
function displayMessage(strMessage) {
alert(strMessage);
};
</script> -->
</head>
<body>
<div id="parameterPopup">
<div class="heading">Enter Parameter Values</div>
<br>
<div class="content"></div>
<br>
<div class="buttons">
<input type="button" value="submit values" id="btnSubmitParams" />
</div>
</div>
<div id="wrapper">
<div id="userInfonLogout">
<p>Welcome <b><%=Username %></b></p>
<center><a href="Logout.jsp" >logout</a></center>
</div>
<div id="topheader">
<div id="logo">
<img src="static/images/CS_200px.png"/>
</div>
<center><div id="headertext"><h1>Data Validation Automation</h1></div> </center>
</div>
<div id="navigation">
<ul>
<li>Home</li>
<li>Projects</li>
<li>Repository</li>
<li>Create Test Scenario</li>
<li>Maintain Test Scenarios</li>
<li>Configuration</li>
</ul>
</div>
<div id="body">
<div id="popup" style="display:none">
<div class="content">
</div>
<input type="button" class="close" value="close"/>
</div>
<h2>
<p align="center">
Create Test Scenario</p></h2>
<%!
FunctionKeywordManager objFunctionKeywordManager;
List<String> listKeywords;
TestScenarioManager objTestScenarioManager;
ReportGenerator objReportGenerator=new ReportGenerator();
public void jspInit(){
objFunctionKeywordManager = new FunctionKeywordManager();
listKeywords = objFunctionKeywordManager.getAllFunctionKeyword();
objTestScenarioManager = new TestScenarioManager();
}
%>
<%
RepositoryManager objRM = new RepositoryManager();
List<String> listRepo = objRM.getRepositoryListForProject(projectName);
%>
P.S: A newbie to jsp and tomcat.
Thanks in advance.
I'm writing a wizard for creating a user in my application with Spring MVC. At each step the controller will set session attributes for the completed wizard fields.
I want the wizard to look the same regardless of which page it's on, except for each page's fields, obviously. For example, menus and links at the top of the page and buttons at the bottom should remain the same.
I have the following JSP
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Create a new User</title>
</head>
<body>
<h1>User Creation Wizard</h1>
Step <c:out value = "${pageNum}"/>/<c:out value = "${pageMax}"/>
<form action="" method="POST">
<jsp:include page="userform${pageView}.jsp"/>
<input name = "currentPage" type = "hidden" value = "${pageNum}"/>
<c:if test = "${pageNum > 1}">
<input name = "prev" type = "submit" value = "Previous" />
</c:if>
<c:if test = "${pageNum < pageMax}">
<input name = "next" type = "submit" value = "Next" />
</c:if>
<c:if test = "${pageNum == pageMax}">
<input name = "submit" type = "submit" value = "Finish" />
</c:if>
</form>
</body>
</html>
In the jsp I'm including, do I need to remove the <html>, <head>, and <body> tags? The above code is based on this example.
Yes, you'd need to remove the <html>, <head> and <body> tags from the included JSP file. As they'd already be present in the including file keeping them would result in invalid HTML.
Only the content that you want to vary would be in the JSP file you're including. Everything else, including the necessary <html>, <head> and <body> tags, would be in the JSP file that does the including.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I've written the below JSP. Now I want to make it into a MVC pattern, could you please help me how to do it?
<%#page import="java.util.Date"%>
<%#include file="DBCon.jsp" %>
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script language="javascript">
function UnBloc1(test){
var temp3id= 'temp3' + test;
var temp4id= 'temp4' + test;
//alert(temp3id);
document.getElementById(temp3id).style.display='block';
document.getElementById(temp4id).style.display='block';
}
function invoke(but1)
{
//var x=document.getElementById("temp3"+but).value;
//alert(x);
document.abc.action="Up_Query_DB.jsp?val1="+but1;
document.abc.submit();
}
function invoke1(but)
{
document.abc.action="Users_2.jsp?val="+but;
document.abc.submit();
//var t=document.getElementById("ab")+z;
//alert(t);
}
</script>
</head>
<body>
<form name="abc" method="post" action=""><table>
<%
try
{
String s=(String)session.getAttribute("muusername");
int i=0;
int temp=0, temp1=0,temp2=0, temp3=0, temp4=0;
ps=con.prepareStatement("Select DBID,Query_Raised,TR from Scope2 where TR!='null' AND (Query_Answered is null OR Count1 is null) And Specialist='"+s+"'");
rs=ps.executeQuery();
out.println("<b>QueryRaised</b>");
while(rs.next())
{
i++;
%>
<tr>
<td><input type="text" value="<%=i%>" name="id1" id="id1"></td>
<td><center><input type="text" value="<%=rs.getString("DBID")%>" readonly id="abc<%=i%>" name="abc<%=i%>" size="100"></center></td>
<td><input type="Submit" value="Resume" name="temp1<%=i%>" id="temp1<%=i%>" onclick="invoke1(<%=i%>)"></td>
<td><input type="button" value="Update Answer" name="temp2<%=i%>" id="temp2<%=i%>" onClick="UnBloc1(<%=i%>)"></td>
<td><input type="text" name="temp3<%=i%>" id="temp3<%=i%>" style="display: none"/></td>
<td><input type="Submit" value="Submit Answer" name="temp4<%=i%>" id="temp4<%=i%>" style="display: none" onClick="invoke(<%=i%>)"/> </td>
</tr>
<% }
}
catch(Exception e)
{
out.println(e);
}
%>
</table>
</form>
</body>
</html>
Let's say you go to the database and get a list of objects that contain few attributes (with setter and getter methods), among them, the dbid attribute. The object would be your model. Let's call it myBean.
The Java class from you will do the query will be the Controller class. Let's call it myController. So, the controller should: 1. Get the list of objects you need. 2. Do anything that should be done before representing the information (in your case, I would say nothing) and 3. pass the information to the JSP through the list of your beans setting the information in the request so the information can be displayed.
Your JSP, now, should look like this:
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script language="javascript">
...
</script>
</head>
<body>
<form name="abc" method="post" action="">
<table>
<c:forEach var="myItem" items="${listDbid}" varStatus="i">
<tr>
<td><input type="text" value="${i.count}" name="id1" id="id1"></td>
<td><center><input type="text" value="${myItem.getDbid}" readonly id="abc${i.count}" name="abc${i.count}" size="100"></center></td>
<td><input type="Submit" value="Resume" name="temp1${i.count}" id="temp1${i.count}" onclick="invoke1(${i.count})"></td>
<td><input type="button" value="Update Answer" name="temp2${i.count}" id="temp2${i.count}" onClick="UnBloc1(${i.count})"></td>
<td><input type="text" name="temp3${i.count}" id="temp3${i.count}" style="display: none"/></td>
<td><input type="Submit" value="Submit Answer" name="temp4${i.count}" id="temp4${i.count}" style="display: none" onClick="invoke(${i.count})"/> </td>
</tr>
</c:forEach>
</table>
</form>
</body>
</html>
So, basically, you need to remove from your JSP all the code that is not "view", take it to a "controller" and use a "model" for sending the information from the "controller" to the "view".
Also
You should avoid scriptles (<% %>) in your JSP, better to use JSTL and others similar tools. If you do it, probably your JSP will not have "controller" code.
I recommend you to use a MVC framework, like Spring MVC or Struts, among others.
It is also nice if you create another layer in your code just for database access. This database layer will be used by the controllers so the controllers. You can reuse code, make controllers independent of database and keep them clearer.
I am new too MVC as well, but I can suggest you some tips. Make a bean. Beans are Java class with getter and setter. In your case the bean would be
public class Scope2
{
String dbID;
//all other attributes of the table.Beans should be reusable so usually there is only one bean for one corresponding table
public String getDBID()
{
return dbID;
}
public void setDBID(String dbId)
{
this.dbId=dbId;
}
//Other getters and setters for all other attributes
}
Now make a class that would perform database query. And return bean Scope2 from that class to jsp. And in your jsp you will simply print the values as out.println(bean.getDBID());