Triggered
asked on
using Spaces with jsp paramters
Hi,
My problem is im using javascript that displays an error message based the input name ,
say my input name is "MobileNumber" is displays "MobileNumber" should a be a number blah blah.....
but i want to display "Mobile Number" should be a number, but if use this im messing up other code in servlets that cant use
request.getParameter("Mobi le Number");
tried using request.getParameter("Mobi le+Number" ); but it doesnt seem to work
Any suggestions,
Triggered
My problem is im using javascript that displays an error message based the input name ,
say my input name is "MobileNumber" is displays "MobileNumber" should a be a number blah blah.....
but i want to display "Mobile Number" should be a number, but if use this im messing up other code in servlets that cant use
request.getParameter("Mobi
tried using request.getParameter("Mobi
Any suggestions,
Triggered
As Nick says the name of the parameter does not matter, I think that Nick thought at the other question that you wanted to put spaces on the VALUE of the parameter not on the name like this
http://www.yourweb.com/yourJsp.jsp?MOBILE NUMBER=+ 34 670 09 09 09
That will get messed but not the Param name itself.
Javier
http://www.yourweb.com/yourJsp.jsp?MOBILE NUMBER=+ 34 670 09 09 09
That will get messed but not the Param name itself.
Javier
ASKER
in my servlet i have
String MobileNumber = String.valueOf(request.get
System.out.println("Mobile
but it falls over when i do the following
Integer.parseInt(MobileNum
,but if my input name is changed to "MobileNumber" instead of using "Mobile Number" everything works??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just one thing, Why you use a Mobile Number as an Integer?
Anyway try to see if works to do this:
Integer MobileNumber = new Integer(request.getParamet er("Mobile Number"));
Javier
Anyway try to see if works to do this:
Integer MobileNumber = new Integer(request.getParamet
Javier
>Just one thing, Why you use a Mobile Number as an Integer?
To clarify this:
I don't know if you've readed my profile but I've been working all my life for a Phone company an never used the "Number of the line" as Numeric.
:c)
Javier
To clarify this:
I don't know if you've readed my profile but I've been working all my life for a Phone company an never used the "Number of the line" as Numeric.
:c)
Javier
ASKER
still not working, business rules mean i have to use numbers....would make my job much easier if we had'nt to, but thats another story :-)
Are you doing a post or a get to the servlet??? because as other experts have said.. having a space in the parameter doesn't matter is should still be working.....
you might get in to the problems if you are making the url in the javascript and then sending it over to servlet.
In that case you will have to use escape method of script over your variables.
you might get in to the problems if you are making the url in the javascript and then sending it over to servlet.
In that case you will have to use escape method of script over your variables.
Yup.... Post the code Triggered pls.
I guess I should point out that my answer above avoids the problem/diffficulty you are having putting spaces in your parameter names. It adds the spaces at the point where you are using javascript to display an error message.
Yes I agree but we are trying to put the point that parameter names with spaces DOES work...
yours is a easy way out of it....:-)
yours is a easy way out of it....:-)
ASKER
my html page has the following:-
<FORM METHOD=POST ACTION="servlet/storedetai
where "Mobile Number" is declared as
<input name="Mobile Number" type="text" id="Mobile Number">
..........................
heres the servlet code:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import Myproj.DBConectionManager;
public class storedetailservlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html";
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
public void doPost( HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
HttpSession session = request.getSession();
String MemberID= (String)session.getAttribu
String MobileNumber= String.valueOf(request.get
dbCon.storeDetails(MemberI
RequestDispatcher Dispatche=request.getReque
}
//Clean up resources
public void destroy() {
}
}
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import Myproj.DBConectionManager;
public class storedetailservlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html";
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
public void doPost( HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
HttpSession session = request.getSession();
String MemberID= (String)session.getAttribu te("Member ID");
int num=0;
String MobileNumber=request.getPa rameter("M obile Number");
MobileNumber = MobileNumber.trim();
System.out.println("got the Number as "+MobileNumber);
try{
num=Interger.parseInt(Mobi leNumber);
}catch(java.lang.NumberFor matExcepti on)
{
System.out.println("Error Formating the Number, it might not be a valid Number");
}
dbCon.storeDetails(MemberI D,num);
RequestDispatcher Dispatche=request.getReque stDispatch er("myAcco unt.jsp");
}
//Clean up resources
public void destroy() {
}
}
Try this
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import Myproj.DBConectionManager;
public class storedetailservlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html";
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
public void doPost( HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
HttpSession session = request.getSession();
String MemberID= (String)session.getAttribu
int num=0;
String MobileNumber=request.getPa
MobileNumber = MobileNumber.trim();
System.out.println("got the Number as "+MobileNumber);
try{
num=Interger.parseInt(Mobi
}catch(java.lang.NumberFor
{
System.out.println("Error Formating the Number, it might not be a valid Number");
}
dbCon.storeDetails(MemberI
RequestDispatcher Dispatche=request.getReque
}
//Clean up resources
public void destroy() {
}
}
Try this
ASKER
ill try that but ill b pleasantly suprised if it works as the servlet was prnting out "null" awhile ago when i had in a system.out.() for the "Mbile Number"
Resorting to w3 docs again, it appears you are NOT allowed spaces in name attributes:
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
http://www.w3.org/TR/REC-html40/types.html#type-cdata
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
http://www.w3.org/TR/REC-html40/types.html#type-cdata
Ah shhhugar.
Forget that. I misread the spec.
Forget that. I misread the spec.
IMO, although you CAN have space in name, I'll never do it in my life.
searlas is right that you can always do something in javascript to restore those spaces.
searlas is right that you can always do something in javascript to restore those spaces.
I agree with Kenneth. but as triggered is using a servlet he should implement searlas Javascript Function as a Java one in his servlet.
I guess it will work as is in Java right?
And of course searlas should get the points. but as Kuldeepchaturvedi says we where trying to know why triggered can't get that working with the spaces in, wich is a good question too.
Javier
I guess it will work as is in Java right?
And of course searlas should get the points. but as Kuldeepchaturvedi says we where trying to know why triggered can't get that working with the spaces in, wich is a good question too.
Javier
ASKER
Sorry for not getting back sooner,searlas that worked perfectly...thanks a million
>>but if use this im messing up other code in servlets that cant use
>>request.getParameter("Mo
You should be able to use a space like that. Look at the small example below:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
</head>
<body>
<form action="#" method="post">
<table>
<tr>
<td><input type="text" name="Mobile Number"><input type="submit" name=""></td>
</tr>
</table>
</form>
<%
out.println(request.getPar
%>
</body>
</html>