ive got a servlet with a class file contained within file path webapps/ass2/WEB-INF/classes/User.class, the class represents a user bean required for my application. In jsp, ive go the imports organised as `<%#page import="mypck.User" %>. im being thrown an error by apache tomcat when i try to load the page,
An error occurred at line: 12 in the jsp file: /fourm.jsp
User cannot be resolved to a type
9:
10: <head>
11: <%
12: User user = (User)session.getAttribute("userBean");
13:
14: String username = user.getName();
15:
i guess i havent imported the class correctly then? my question is: how do i import this class to the jsp file
a class file contained within file path webapps/ass2/WEB-INF/classes/User.class
...
<%#page import="mypck.User" %>
This doesn't match. The User.class has got to be placed in the mypck folder representing the package. Fix it accordingly: webapps/ass2/WEB-INF/classes/mypck/User.class.
Unrelated to the concrete problem, using scriptlets is discouraged since a decade. I recommend to take a JSP pause and invest some time in learning taglibs and EL. With EL, you can just show the username like follows:
<p>Welcome, ${userBean.name}</p>
See also:
How to avoid Java code in JSP files?
Our EL wiki page
Your import is correct syntax-wise, but is the package declaration correct?
Related
Take the index page for example:
<h1>Hello, world!</h1>
Welcome to your new app.
<SurveyPrompt Title="How is Blazor working for you?" />
It is my understanding that this will be translated into some code using the RenderTreeBuilder which may look something like this:
builder.OpenElement(0, "h1")
builder.AddContent(1, "Hello, world!")
.
.
.
Is there a place where I can inspect the RenderTreeBuilder version of the razor pages?
I would like to start trying out RenderTreeBuilder and would like to know how it is done, for references purposes.
Apologies in advanced if this is a duplicate. I will delete this question if so.
Thanks!
You are right. The BlazorMarkup is translated into C# files that are using the RenderTreeBuilder. It is comparable to what WPF does when it comes to XAML and C# files.
After you have built your project, go to the obj/debug/net5.0/Razor/.
Keep in mind to use a debug build. Otherwise, you won't see the files.
You will see the same directory structure as in your project. Directories are listed as long as they contain razor files. Open the file, e.g., Index.razor.g.cs (.g stands for generated), and you can see the calls to RenderTreeBuilder
[Microsoft.AspNetCore.Components.RouteAttribute("/")]
public partial class Index : Microsoft.AspNetCore.Components.ComponentBase
{
#pragma warning disable 1998
protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
{
__builder.AddMarkupContent(0, "<h1>Hello, world!</h1>\r\n\r\nWelcome to your new app.\r\n\r\n");
__builder.OpenComponent<BlazorApp1.Shared.SurveyPrompt>(1);
__builder.AddAttribute(2, "Title", "How is Blazor working for you?");
__builder.CloseComponent();
}
#pragma warning restore 1998
}
I'm getting a compile error "Type 'commonClass' is not defined" in a file directly beneath the project (\\alf.aspx > alf.aspx.vb) on this line of code:
Dim pDAO As New commonClass
There is such a class, in \\App_Code\commonClass.vb:
Public Class commonClass
What is needed for "alf" to see "commonClass"?
This is probably a very basic (no pun intended) question, but I am a newbie to VB.
UPDATE
Does this have anything to do with the code in the legacy project "seeing" the other code, and the new one not: in the legacy project, the Visual Studio menu items are:
FILE
EDIT
VIEW
**WEBSITE**
BUILD
DEBUG
. . .
...whereas in the new project, they are:
FILE
EDIT
VIEW
**PROJECT**
BUILD
DEBUG
. . .
IOW, the new project (which I created using File > New Project > Templates > VB > New Project) has a "PROJECTS" menu item, whereas the legacy project has a "WEBSITE" menu item.
Will re-doing it as File > New Website > ... make the difference? Is there a way to change it to a website without going through that?
UPDATE 2
Both the legacy code, which compiles, and the new project, which doesn't, contain:
// alf.aspx.vb
Partial Class alf
Inherits Page
-and:
// App_Code\commonClass.vb
Public Class commonClass
I see no "Namespace" in either file...
UPDATE 3
So, wondering if the fact that I created a new project rather than a new website is the crux of the problem, I tried creating a new website, but it tells me, "An item with the same key has already been added" and then the WebSite project - which I have not touched beyond creating it - starts off with 21 Errors and 13 Warnings
You have two files. One for your asp.net file (alf.aspx.vb) and one for your commonClass (I assume commonClass.vb). Do both of these files have a Namespace defined and are they both the same Namespace (alf)? If they don't match then you will get the error you are describing.
Namespace alf
Public Class commonClass
Public Shared Sub Execute()
Console.WriteLine("Blah")
End Sub
End Class
End Namespace
I solved this wide-ranging and confounding issue with a three-pronged approach, which is detailed here.
We are using custom-written proxy class for handling the Web Service communication provided by Mihai Cadariu (screenshot attached) for resolving dynamic linking.
For forming the LinkUrl parameters to resolve dynamiclink/component link we are following the below sample approach. But its throwing error (stacktrace,debug error)attached .Please validate and provide the inputs where we are going wrong. Please let us know the parameters we are passing are correct or not
Approach we used:
-->We have two components Comp1,Comp2 (can be created of same/different schema guess it not any issue)
-->Comp2 is being used as component link inside Comp1 (we have a component link field in comp1)
-->Created two dynamic CT’s DCT1, DCT2 for each comp (CT’s have simple DWT, Default finish actions)
Note: also tried keeping DD4T TBBs in similar set of CT’s as other approach but final got same error result
-->DWT code has --> SomeLink (to render component link so that LinkResolver TBB will resolve the links)
Also kept OTHWayLink (for cross checking)
-->Created two Pages Page1 (has Comp1+DCT1), Page2 (has Comp2 +DCT2) and published both pages to broker DB
-->Our goal is to resolve component link (Comp2) which is present inside Comp1 content so,
-->For GetDynamicLink() we provided parameters as given below. Which throwed error :400 (bad request) and exception in log trace attached above.
Param’s List --> string targetPageUri, string targetComponentUri, string targetTemplateUri, string linkText, bool showTextOnFail, string linkTagAttributes
Param’s we passed--> Page2 tcmid, Comp2 tcmid, DCT2 tcmid ,”some link txt”,true,”some string”;
-->For GetComponentLink()we provided parameters as given below. In this case we tried keeping both dynamic and non dynamic CT’s combination inside pages, Which also throwed error :400 (bad request) and exception in log trace attached above.
Param’s List --> string targetComponentUri, string sourcePageUri, string excludeTemplateUri, string linkText, bool showTextOnFail, bool showAnchor, string linkTagAttributes
Param’s we passed --> Comp2 tcmid, Page1 tcmid, DCT1 tcmid, “some link txt”,true,true,”some string” ;
we are refering Live documentation for Linking.
Mihai Proxy Code sample:
Error message:
Looks to me like your odata website is not set up correctly in d:/inetpub/wwwroot/odata/bin as the error message is that Classes are not found.
Can you confirm you've installed/placed the correct SDL Tridion dll/lib and configuration XML files into your website?
Here is a great post about how SDL Tridion loads these files: http://www.tridiondeveloper.com/how-tridion-content-delivery-loads-configuration-files-in-dotnet I'm sure once you've got the Odata application/website up and running this will work correctly for you.
The Content Delivery linking service's parameters are documented on this page (log in required). I'll paste an excerpt below, but you really should simply compare your strings to the parameters mentioned on that page.
Component Links
Command:/linking/componentLink (Java) or /linking.svc/componentLink (.NET)
Input parameters:
Parameter name Default value
sourcePageURI (none)
targetComponentURI (none)
excludeTemplateURI (none)
linkTagAttributes (empty)
linkText (empty)
showTextOnFail true
showAnchor false
From cross-checking these with the code you pasted in the screenshot, everything seems to line up.
That answer your question. But I doubt it solves your problem, since that seems (as John Winter suggested) more infrastructural: you're missing cd_link.jar in the relevant directory.
If you find it difficult to diagnose this problem further, I suggest contacting the original author of this custom code (or SDL or one of its partners). This will ensure you get help from someone who is experienced in troubleshooting the loading of JARs, DLLs and configuration files.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Razor-based view doesn't see referenced assemblies
I am a Newbie in ASP.net
I am trying to connect to a database and I keep getting this error
**Compilation Error
Description: An error occurred during the compilation of a resource
required to service this request. Please review the following specific
error details and modify your source code appropriately.
Compiler Error Message: CS0103: The name 'Database' does not exist in
the current context
Source Error:
Line 1: #{
Line 2: var db = Database.Open("demo"); '
Line 3:
Line 4:
Source File: c:\Users\Ayoya\Documents\My Web Sites\demo\Page.cshtml
Line: 2
**
Can anyone tell me whats wrong?
Thank you
The compiler's already telling you what's wrong - it doesn't know what you mean by Database. Is that mean to be a property of the page, or is it the name of a type with a static Open method? It's not clear from the code itself, and obviously the compiler can't find the name either.
Work out what name you mean, then work out why the compiler can't see it, then fix that. If you need more help on any of these steps, you'll need to provide more information.
(As an aside, I completely agree with dbaseman: putting database calls in your view is a bad idea.)
If you're opening a database in your Razor view, that is completely the wrong approach. Your logic should go in the Controller, not the View. Consider creating a "view model" class that contains all the data needed for your view, and populate that class from the Controller.
Probably the reason this piece of code isn't working is that you will need to specify the full namespace of Database. I'm not sure what that class is, though; if it's in a separate DLL, you'll have more problems. Again, though, you should circumvent this problem by putting your database logic in the controller.
I received a Flex project and when trying to compile it i get a few 1046 errors that say the Type was not found or was not a compile-time constant MyClass
however - the respective files are listed on the top of the file in an import clause like this:
import com.folder1.folder2.folder3.MyClass;
and if i check the folder structure, MyClass.as is there.
however, if i type this same line (import com.folder1.folder2.folder3.MyClass;) and check at each . what the autocompletion suggests, I see only a subset of the as classes that are actually there on the harddisk.
What determines which classes and folders are suggested by the autocompletion function? I don't get any compile error on the corresponding import statements that import MyClass
//edit:
screenshot 1 shows the file in which the error occurs that tries to import the class in question (Updater)
http://neo.cycovery.com/flex_problem.gif
screenshot 2 shows the file Updater.as
http://neo.cycovery.com/flex_problem2.gif
the censored part of the path matches in both cases (folder structure and package statement in Updater.as)
screenshot 3 shows where the error actually happens:
http://neo.cycovery.com/flex_problem3.gif
interestingly, the variable declaration
private var _updater:Updater = new Updater();
further up in the file does not give an error
This project is set up wrong. Its obvious your application can not find the classes.
Move your "com" folder and all of the contents into your "src" folder.
Or perhaps include the files in your source path?
right click on the project name->properties->flex Build Path->add folder
the import is based on the 'package' declaration within the file itself (at the top of the file). If the file's package declaration does not match the actual folder structure, you will get problems.
Check the classes you can't see in the autocompletion list. Maybe those classes' package name doesn't match the actual structure.
Rob
Check your actionscript source paths. Any chance that the folders you are seeing (events and objects) are in there explicitly, and the others are not? Normally, you have all your source inside a folder like src that is in the source path, so that the compiler can find anything anywhere inside it. But you can just as easily make your source paths too specific and just see a few things...